I'm kinda new to VBA and I've searched through google plenty of times with no results so here I go....


How do I use an if statements in vba for excel's macro?
So let's say I have this number "105200".

I want an if statement that checks if the number in cell "H1" is the same as "105200". The thing is, this "105200" number changes for every file, to maybe "105600" or "109300", so it's easier if I ask the user for the "105200" number, and then set it as let's say "x".

When I do this:

[VBA]
If Cells(1,1)= "105200" Then
Sheets(result).Select
Cells(newcount, 2).Select
ActiveSheet.Paste
ElseIf Cells(1,1)= "109200" Then
Sheets(result).Select
Cells(newcount, 3).Select
ActiveSheet.Paste
End If[/VBA]

The macro worked...

Then, I changed the "105200" to x and defined x = "105200" as such:

x1 = "105200"
x2 = "109200"
[VBA]
If Cells(1,1)= x1 Then
Sheets(result).Select
Cells(newcount, 2).Select
ActiveSheet.Paste
ElseIf Cells(1,1)= x2 Then
Sheets(result).Select
Cells(newcount, 3).Select
ActiveSheet.Paste
End If[/VBA]


and it doesn't work... I've been looking at this thing for 6 hours and can't figure out why...

What should I put as x ?