PC Review


Reply
Thread Tools Rate Thread

Can't get the If and Else statement correct

 
 
Corey ....
Guest
Posts: n/a
 
      29th Jul 2008
I using the below to find IF a set of 2 cell values exist in another sheet.

If they Do exist then i need to run say Macro1.
If they do NOT exist then i need to run say Macro2.

I can't seem to get the ELSE statement correct.
Thet either BOTH run or NONE.


~~~~~~~~~~~~~~~~~~~~~~
Sub AlreadyThere()
' Check to see if it Already exists
With Workbooks("TSS")
' "Data" Sheet3 is NOT Sheet's "Data"
Dim rngFound As Range
On Error Resume Next
With Worksheets("Data").Range("A:A")
Set rngFound = .Find(What:=Sheet4.Range("D2").Value, After:=.Cells(1),
LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows,
SearchDirection:=xlNext, MatchCase:=False, Matchbyte:=False)
If rngFound.Value = Sheet4.Range("D2").Value And rngFound.Offset(0,
1).Value = Sheet4.Range("K2").Value Then
' Do THIS
Else: 'DO THAT
End If
End With
End With
End Sub
~~~~~~~~~~~~~~~~~~~~~~


I am pretty sure it is a simple matter of getting the ELSE or ELSEIF
statement correct to saolve it.

Corey....


 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      29th Jul 2008
Sub AlreadyThere()
' Check to see if it Already exists
With ActiveWorkbook 'Workbooks("TSS")

' "Data" Sheet3 is NOT Sheet's "Data"
Dim rngFound As Range
On Error Resume Next
With Worksheets("Data").Range("A:A")

Set rngFound = .Find(What:=Sheet4.Range("D2").Value, _
After:=.Cells(1), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
Matchbyte:=False)
If Not rngFound Is Nothing Then

If rngFound.Offset(0, 1).Value = Sheet4.Range("K2").Value
Then
' Do THIS
Else
' DO THAT
End If
Else
' DO THAT
End If
End With
End With
End Sub


--
__________________________________
HTH

Bob

"Corey ...." <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I using the below to find IF a set of 2 cell values exist in another sheet.
>
> If they Do exist then i need to run say Macro1.
> If they do NOT exist then i need to run say Macro2.
>
> I can't seem to get the ELSE statement correct.
> Thet either BOTH run or NONE.
>
>
> ~~~~~~~~~~~~~~~~~~~~~~
> Sub AlreadyThere()
> ' Check to see if it Already exists
> With Workbooks("TSS")
> ' "Data" Sheet3 is NOT Sheet's "Data"
> Dim rngFound As Range
> On Error Resume Next
> With Worksheets("Data").Range("A:A")
> Set rngFound = .Find(What:=Sheet4.Range("D2").Value, After:=.Cells(1),
> LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows,
> SearchDirection:=xlNext, MatchCase:=False, Matchbyte:=False)
> If rngFound.Value = Sheet4.Range("D2").Value And rngFound.Offset(0,
> 1).Value = Sheet4.Range("K2").Value Then
> ' Do THIS
> Else: 'DO THAT
> End If
> End With
> End With
> End Sub
> ~~~~~~~~~~~~~~~~~~~~~~
>
>
> I am pretty sure it is a simple matter of getting the ELSE or ELSEIF
> statement correct to saolve it.
>
> Corey....
>



 
Reply With Quote
 
Corey
Guest
Posts: n/a
 
      29th Jul 2008
Thank you very much Bob.
You are a true gentleman.

I think i got lost int he If and If Not's etc ....


Corey....
"Bob Phillips" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Sub AlreadyThere()
> ' Check to see if it Already exists
> With ActiveWorkbook 'Workbooks("TSS")
>
> ' "Data" Sheet3 is NOT Sheet's "Data"
> Dim rngFound As Range
> On Error Resume Next
> With Worksheets("Data").Range("A:A")
>
> Set rngFound = .Find(What:=Sheet4.Range("D2").Value, _
> After:=.Cells(1), _
> LookIn:=xlValues, _
> LookAt:=xlWhole, _
> SearchOrder:=xlByRows, _
> SearchDirection:=xlNext, _
> MatchCase:=False, _
> Matchbyte:=False)
> If Not rngFound Is Nothing Then
>
> If rngFound.Offset(0, 1).Value = Sheet4.Range("K2").Value
> Then
> ' Do THIS
> Else
> ' DO THAT
> End If
> Else
> ' DO THAT
> End If
> End With
> End With
> End Sub
>
>
> --
> __________________________________
> HTH
>
> Bob
>
> "Corey ...." <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>I using the below to find IF a set of 2 cell values exist in another
>>sheet.
>>
>> If they Do exist then i need to run say Macro1.
>> If they do NOT exist then i need to run say Macro2.
>>
>> I can't seem to get the ELSE statement correct.
>> Thet either BOTH run or NONE.
>>
>>
>> ~~~~~~~~~~~~~~~~~~~~~~
>> Sub AlreadyThere()
>> ' Check to see if it Already exists
>> With Workbooks("TSS")
>> ' "Data" Sheet3 is NOT Sheet's "Data"
>> Dim rngFound As Range
>> On Error Resume Next
>> With Worksheets("Data").Range("A:A")
>> Set rngFound = .Find(What:=Sheet4.Range("D2").Value, After:=.Cells(1),
>> LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows,
>> SearchDirection:=xlNext, MatchCase:=False, Matchbyte:=False)
>> If rngFound.Value = Sheet4.Range("D2").Value And rngFound.Offset(0,
>> 1).Value = Sheet4.Range("K2").Value Then
>> ' Do THIS
>> Else: 'DO THAT
>> End If
>> End With
>> End With
>> End Sub
>> ~~~~~~~~~~~~~~~~~~~~~~
>>
>>
>> I am pretty sure it is a simple matter of getting the ELSE or ELSEIF
>> statement correct to saolve it.
>>
>> Corey....
>>

>
>



 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      29th Jul 2008
You also need to test whether a match was found. By doing that, no need to
test if the found cell is the same as the lookup value, it must be.

--
__________________________________
HTH

Bob

"Corey" <(E-Mail Removed)> wrote in message
news:%23ufHB$(E-Mail Removed)...
> Thank you very much Bob.
> You are a true gentleman.
>
> I think i got lost int he If and If Not's etc ....
>
>
> Corey....
> "Bob Phillips" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Sub AlreadyThere()
>> ' Check to see if it Already exists
>> With ActiveWorkbook 'Workbooks("TSS")
>>
>> ' "Data" Sheet3 is NOT Sheet's "Data"
>> Dim rngFound As Range
>> On Error Resume Next
>> With Worksheets("Data").Range("A:A")
>>
>> Set rngFound = .Find(What:=Sheet4.Range("D2").Value, _
>> After:=.Cells(1), _
>> LookIn:=xlValues, _
>> LookAt:=xlWhole, _
>> SearchOrder:=xlByRows, _
>> SearchDirection:=xlNext, _
>> MatchCase:=False, _
>> Matchbyte:=False)
>> If Not rngFound Is Nothing Then
>>
>> If rngFound.Offset(0, 1).Value = Sheet4.Range("K2").Value
>> Then
>> ' Do THIS
>> Else
>> ' DO THAT
>> End If
>> Else
>> ' DO THAT
>> End If
>> End With
>> End With
>> End Sub
>>
>>
>> --
>> __________________________________
>> HTH
>>
>> Bob
>>
>> "Corey ...." <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>>I using the below to find IF a set of 2 cell values exist in another
>>>sheet.
>>>
>>> If they Do exist then i need to run say Macro1.
>>> If they do NOT exist then i need to run say Macro2.
>>>
>>> I can't seem to get the ELSE statement correct.
>>> Thet either BOTH run or NONE.
>>>
>>>
>>> ~~~~~~~~~~~~~~~~~~~~~~
>>> Sub AlreadyThere()
>>> ' Check to see if it Already exists
>>> With Workbooks("TSS")
>>> ' "Data" Sheet3 is NOT Sheet's "Data"
>>> Dim rngFound As Range
>>> On Error Resume Next
>>> With Worksheets("Data").Range("A:A")
>>> Set rngFound = .Find(What:=Sheet4.Range("D2").Value, After:=.Cells(1),
>>> LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows,
>>> SearchDirection:=xlNext, MatchCase:=False, Matchbyte:=False)
>>> If rngFound.Value = Sheet4.Range("D2").Value And rngFound.Offset(0,
>>> 1).Value = Sheet4.Range("K2").Value Then
>>> ' Do THIS
>>> Else: 'DO THAT
>>> End If
>>> End With
>>> End With
>>> End Sub
>>> ~~~~~~~~~~~~~~~~~~~~~~
>>>
>>>
>>> I am pretty sure it is a simple matter of getting the ELSE or ELSEIF
>>> statement correct to saolve it.
>>>
>>> Corey....
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is this statement correct Tony Johansson Microsoft C# .NET 0 13th Feb 2011 01:03 PM
IF Statement - Correct Function? MJS Microsoft Excel Misc 6 13th Feb 2009 02:55 AM
which statement right , question is Choose the correct statement? =?Utf-8?B?aG93IG1hbnkgdGVtcGxhdGU/d2hlbiB3ZSBjbGlj Microsoft Word Document Management 1 16th Oct 2006 11:15 AM
which statement right , question isChoose the correct statement? =?Utf-8?B?aG93IG1hbnkgdGVtcGxhdGU/d2hlbiB3ZSBjbGlj Microsoft Word Document Management 1 15th Oct 2006 11:20 PM
Correct SQL Statement =?Utf-8?B?Q2hyaXM=?= Microsoft Access VBA Modules 1 4th Oct 2005 06:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:31 AM.