VBA Select Cell On Multiple Sheets

julia55

Board Regular
Joined
Dec 2, 2010
Messages
73
I am trying to have an input box prompt for a cell number, and then select that cell on all of the sheets in my workbook. The sheet names and number of sheets will vary each time. This is what I have so far, but of course it is making me enter the cell number multiple times for each sheet and I would rather only have to enter it once.

Code:
Sub SelectCells()
Application.ScreenUpdating = False
 
Dim i As Integer
Dim currentsheet As Worksheet
For i = 1 To ActiveWorkbook.Worksheets.Count
Set currentsheet = ActiveWorkbook.Worksheets(i)
Worksheets(i).Activate
Dim MyRange As Range
Set MyRange = Application.InputBox(Prompt:= _
                "Please enter the cell number you would like to select.", _
                    Title:="SPECIFY CELL", Type:=8)
MyRange.Select
Next i
Application.ScreenUpdating = True
Sheets("Total IX Series").Select
 
End Sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Hi julia55,

The reason you are being asked for the cell details for each sheets is because you've put the input in the middle of the For / Next Try this
Code:
Sub SelectCells()
Application.ScreenUpdating = False
 
Dim i As Integer
Dim currentsheet As Worksheet
Dim MyRange As Range
Set MyRange = Application.InputBox(Prompt:= _
                "Please enter the cell number you would like to select.", _
                    Title:="SPECIFY CELL", Type:=8)
 
For i = 1 To ActiveWorkbook.Worksheets.Count
Set currentsheet = ActiveWorkbook.Worksheets(i)
Worksheets(i).Activate
MyRange.Select
Next i
Application.ScreenUpdating = True
Sheets("Total IX Series").Select
 
End Sub

ColinKJ
 
Upvote 0
I tired that, but got an error.. "Run-Time error '1004': Select method of Range class failed."
 
Upvote 0
Hi julia55,

Your code hasn't any checks to ensure that what is entered in the Inputbox is a valid Cell Reference.

What are you entering ?

ColinKJ
 
Upvote 0
I enter Z14 for an example and that's when I got the error message. When I go to debug it highlights the line that states:

Code:
MyRange.Select
 
Upvote 0
Hi julia55,

This works in a test WB I just did.

Code:
Sub SelectCells()
Application.ScreenUpdating = False
 
Dim i As Integer
Dim currentsheet As Worksheet
Dim MyRange As Range
X = InputBox("Enter Cell Ref")
 
For i = 1 To ActiveWorkbook.Worksheets.Count
Set currentsheet = ActiveWorkbook.Worksheets(i)
Worksheets(i).Activate
Range(X).Select
Next i
Application.ScreenUpdating = True
Sheets("Total IX Series").Select

Colin
 
Upvote 0

Forum statistics

Threads
1,224,585
Messages
6,179,704
Members
452,938
Latest member
babeneker

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top