PDA

View Full Version : IF Range Select not working



OldCityCat
02-19-2012, 08:25 AM
Can someone please tell me what is wrong with my code.
The code works up the If statement and I'm not sure why.
When I Step though the code nothing happens in the worksheet after "Sheets("SalesRed").Range("B5").Select"

Thanks for any and all suggestions

Gilc


Private Sub SalesRedeemed_Click()
' Open SalesRedeemed Worksheet move to next month
Sheets("SalesRed").Select
Sheets("SalesRed").Range("B5").Select

If Range("B5").Value > 1 Then
Sheets("SalesRed").Range("B6").Select
End If

End Sub

xld
02-19-2012, 09:21 AM
Private Sub SalesRedeemed_Click()
' Open SalesRedeemed Worksheet move to next month
Sheets("SalesRed").Select
Sheets("SalesRed").Range("B5").Select

If Range("B5").Value > 1 Then
Sheets("SalesRed").Activate
Range("B6").Select
End If
End Sub

OldCityCat
02-19-2012, 09:59 AM
Thanks for your suggestion XLD

I tried your suggestion still seems to be ignoring the IF statement
I also tried adding "Sheets("SalesRed")" it made no difference ether.


Private Sub SalesRedeemed_Click()
' Open SalesRedeemed Worksheet move to next month
Sheets("SalesRed").Select
Sheets("SalesRed").Range("B5").Select

If Range("B5").Value > 1 Then
Sheets("SalesRed").Activate
Range("B6").Select
End If

End Sub


Private Sub SalesRedeemed_Click()
' Open SalesRedeemed Worksheet move to next month
Sheets("SalesRed").Select
Sheets("SalesRed").Range("B5").Select

If Range("B5").Value > 1 Then
Sheets("SalesRed").Activate
Sheets("SalesRed").Range("B6").Select
End If

End Sub

xld
02-19-2012, 11:58 AM
Another try



Private Sub SalesRedeemed_Click()
' Open SalesRedeemed Worksheet move to next month

With Sheets("SalesRed")

If .Range("B5").Value > 1 Then

.Activate
Range("B6").Select
End If
End With
End Sub

OldCityCat
02-19-2012, 12:36 PM
Runtime Error 1004
Select Method of Range class failed
If .Range("B5").Value > 1 Then
.Activate
Debug selected this
Range("B6").Select

mdmackillop
02-19-2012, 02:26 PM
Private Sub SalesRedeemed_Click()
' Open SalesRedeemed Worksheet move to next month
With Sheets("SalesRed")
.Activate
If .Range("B5").Value > 1 Then
.Range("B5").Select
Else
.Range("B6").Select
End If
End With
End Sub

OldCityCat
02-20-2012, 05:48 AM
Thanks to all for your suggestions.
After some trail and error I was able to accomplish what I needed by
Call a sub once the worksheet opened.

Thanks Again
OldCityCat