If statement (1 Viewer)

bgcogen

Registered User.
Local time
Today, 23:52
Joined
Apr 19, 2002
Messages
61
Thanks that static thing worked :)

Another Excel VB question coming, sorry!

Basically I have to check if the first letter in a cell is either D of G, and then perform an action. But I've tried this and it doesn't work:

If Selection = "D" & "*" Then
Do something

ElseIf Selection = "G" & "*" Then
Do something else.

End if

Buy even when the cell contains a first letter od D, it just skips that block.

Any help??

Thanks,
D
 

bgcogen

Registered User.
Local time
Today, 23:52
Joined
Apr 19, 2002
Messages
61
Code

Hi,
This is the code that I'm using;


Sheets("Input").Select
Range("F4").Select

If Selection = "D" & "*" Then

Sheets("Units").Select
Range("B2").Select
Selection = "DCP1"


ElseIf Selection = "G" & "*" Then

Sheets("Units").Select
Range("B2").Select
Selection = "GCP1"


End If
 

Emohawk

What a wicked mullet...
Local time
Today, 23:52
Joined
Mar 14, 2002
Messages
79
Try this :

Code:
Sheets("Input").Select 
Range("F4").Select 

If (Selection Like "D*") or (Selection Like "d*") Then 

Sheets("Units").Select 
Range("B2").Select 
Selection = "DCP1" 

ElseIf (Selection Like "G*") or (Selection Like "g*") Then 

Sheets("Units").Select 
Range("B2").Select 
Selection = "GCP1" 

End If

I'm assuming that Selection contains a String. I haven't done much with VB and excel...
 
Last edited:

Users who are viewing this thread

Top Bottom