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.
 

wigi

Well-known Member
Joined
Jul 10, 2006
Messages
7,944
You can only select cells in the active sheet ( = the one you see in front of you).
 

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,166
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:

eblytopia

New Member
Joined
Jul 11, 2012
Messages
7
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
 

wigi

Well-known Member
Joined
Jul 10, 2006
Messages
7,944
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.
 

Forum statistics

Threads
1,082,306
Messages
5,364,414
Members
400,801
Latest member
julievandermeulen

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top