ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Select.Range function in VB IF statements? (https://www.excelbanter.com/excel-programming/288993-select-range-function-vbulletin-if-statements.html)

lykwid[_3_]

Select.Range function in VB IF statements?
 
Hi,

Private Sub ActivityBrowserButton_Click()

If Range("B6").Value = 1 Then
Sheets("Aerobics").Select

ElseIf Range("B6").Value = 2 Then
Sheets("Aqua").Select
____________________

ElseIf Range("B6").Value = 16 Then
Sheets("Yoga").Select

Else
End If

End Sub

The above code is what I am using for my form. The straight line just
indicates more or less repeat code.

The form looks in cell B6 for a value, and if the value is between 1-16
it will go to the shee I have defined for it. IE, IF B6=1 .. open
"Aerobics".

This part of the form works fine, however I can't select a cell for the
form to go to when it loads the sheet. Could anyone suggest any methods
how to do this?

I've tried:

If Range("B6").Value = 1 Then
Sheets("Aerobics").Select
Range("A6").Select
------------- And I got "Select method of range class failed"

I have also tried:

If Range("B6").Value = 1 Then
Sheets("Aerobics").Range("A6").Select
------------- And I got the exact same error.

If anyone could help I would be very grateful.

Thanks.


---
Message posted from http://www.ExcelForum.com/


Chip Pearson

Select.Range function in VB IF statements?
 

Try

Sheets("Aerobics").Select
Sheets("Aerobics").Range("A6").Select



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

"lykwid " wrote in
message ...
Hi,

Private Sub ActivityBrowserButton_Click()

If Range("B6").Value = 1 Then
Sheets("Aerobics").Select

ElseIf Range("B6").Value = 2 Then
Sheets("Aqua").Select
____________________

ElseIf Range("B6").Value = 16 Then
Sheets("Yoga").Select

Else
End If

End Sub

The above code is what I am using for my form. The straight

line just
indicates more or less repeat code.

The form looks in cell B6 for a value, and if the value is

between 1-16
it will go to the shee I have defined for it. IE, IF B6=1 ..

open
"Aerobics".

This part of the form works fine, however I can't select a cell

for the
form to go to when it loads the sheet. Could anyone suggest any

methods
how to do this?

I've tried:

If Range("B6").Value = 1 Then
Sheets("Aerobics").Select
Range("A6").Select
------------- And I got "Select method of range class failed"

I have also tried:

If Range("B6").Value = 1 Then
Sheets("Aerobics").Range("A6").Select
------------- And I got the exact same error.

If anyone could help I would be very grateful.

Thanks.


---
Message posted from http://www.ExcelForum.com/




lykwid[_4_]

Select.Range function in VB IF statements?
 
Yay, it worked :)

Thanks soo much

--
Message posted from http://www.ExcelForum.com



All times are GMT +1. The time now is 08:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com