For...Next Sheet Help!!!

eblytopia

New Member
Joined
Jul 11, 2012
Messages
7
Public Sub Insert_Identifiers()
Dim count As Integer
For count = 1 To 2
'MY CODE
Sheets(count).Columns("A:A").Select
Next count
End

Can any one tell me what I am doing wrong that I have manually select sheet2 in order for the code to work.
I really am blind sided as to what I am doing wrong.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
You can only select cells in the active sheet ( = the one you see in front of you).
 
Upvote 0
Try this...

Code:
[COLOR=darkblue]Public[/COLOR] [COLOR=darkblue]Sub[/COLOR] Insert_Identifiers()
    [COLOR=darkblue]Dim[/COLOR] count  [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Integer[/COLOR]
    [COLOR=darkblue]For[/COLOR] count = 1 [COLOR=darkblue]To[/COLOR] 2
        [COLOR=green]'MY CODE[/COLOR]
        Application.Goto Sheets(count).Columns("A:A")
    [COLOR=darkblue]Next[/COLOR] count
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]

Also note: you don't have to first select a sheet or a range to do something to it e.g.; this will clear cells in column A on sheet 2 no matter what sheet or range is currently selected.

Sheet(2).Range("A:A").ClearContents
 
Last edited:
Upvote 0
Hey this was a brilliant move but however when the code gets to the 2nd sheet I get a run time error '1004.... That I am really ignorant about
 
Upvote 0
Hey this was a brilliant move but however when the code gets to the 2nd sheet I get a run time error '1004.... That I am really ignorant about

Please post your code here, surrounded by
Code:
 tags. Thank you.
 
Upvote 0

Forum statistics

Threads
1,213,532
Messages
6,114,176
Members
448,554
Latest member
Gleisner2

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