Using a variable in an If statement
On Mar 16, 9:04*pm, Rob wrote:
Hello All,
Is there a way to use a variable in an If statement? *I have collected some
information in one part of my subroutine and would like it to be the
conditional of the If statement like this:
Workbooks(orgFile).Worksheets("Cost Centers").Activate
Range("C2").Select
strGetCostCenter = """" & "790-30-00" & """" & " OR Temp = " & """" &
ActiveCell.Value & """"""
ActiveCell.Offset(1, 0).Range("A1").Select
Do Until ActiveCell = ""
* * strGetCostCenter = strGetCostCenter & " OR Temp = " & """" &
ActiveCell.Value & """"
* * ActiveCell.Offset(1, 0).Range("A1").Select
Loop
If Temp = strGetCostCenter Then
endif
If have looked at the results of the strGetCostCenter variable and it
matches exactely what I would use manually in the If statement.
Any suggestions would be greatly appreciated.
Regards,
Rob
Rob,
I'm not quite sure what you are asking for, but I think you have all
of your pieces in your code already. I've created a simple example
below.
Best,
Matt Herbert
If Temp = strGetCostCenter Then
endif
If Temp = strGetCostCenter Then
'insert your code here
End If
'-----------------------
Sub TestVarInIf()
Dim strName As String
Dim strMyName As String
strName = Range("a1").Value
strMyName = "Rob"
If strName < strMyName Then
MsgBox "The name does not match." & vbLf & vbLf & "The name is: "
& strMyName
End If
End Sub
|