If Range("J1").Text...Then

R

ryguy7272

I can’t see what’s wrong with this:

Range("J1").Select
Selection = "=ReturnUserName()" ‘I have a UDF above this line; not
copied here.....

If ActiveSheet.AutoFilterMode Then
ActiveSheet.AutoFilterMode = False
End If

Rows("1:1").Select
Selection.AutoFilter

If Range("J1").Text = hsmith Then
Sheets("Sheet").Select
Range("A1").Cells = 3
Else
MsgBox ("Unauthorized.")
Sheets("Sheet").Select
Exit Sub
End If

'At this point, I would expect to get a 3 in Cell A1 on Sheet “Sheetâ€, but I
don't!!


The value in J1 is hsmith but the sub always gives me the message box.

If I put something like:

If Range("J1").Text = hsmith = wellis Then
‘ so on and so forth

I get a 3 in Cell A1 on Sheet “Sheetâ€. This seems illogical!!
What am I doing wrong?

Thanks,
Ryan---
 
V

Vergel Adriano

Ryan,

Is hsmith a variable that you declared? I'm guessing not, so try enclosing
hsmith in double quotes:

If Range("A1") = "hsmith" then
' do something
End If


Also if you need to test for 2 values, do it like this:

If (Range("A1") = "hsmith") Or (Range("A1")="wellis") Then
'do something
End If
 
R

ryguy7272

Went to bed way to late and got up way to early.
Now it is obvious. Thanks for pointing that out.
Ryan--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top