• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA Help - looping

Is there any problem in the below code, its not moving to next sheet. Also please modify to exclude one tab and make the changes in all other active tabs. Its quite urgent.


" Dim sh As Worksheet


For Each sh In ActiveWorkbook.Worksheets


Range("D2").Select

ActiveCell.FormulaR1C1 = "LC"


Next sh"


Regards

Jay
 
You can also simplify:


Range("D2").Select

ActiveCell.FormulaR1C1 = "LC"


To


Range("D2").FormulaR1C1 = "LC"
 
Hi Jay ,


Try this :

[pre]
Code:
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Worksheets
sh.Range("D2").FormulaR1C1 = "LC"
Next sh
[/pre]
Narayan
 
Hi Jaydev,


Try this.


Sub SheetsLoop()

Dim WS_Count As Integer

Dim I As Integer


WS_Count = ActiveWorkbook.Worksheets.Count


For I = 1 To WS_Count

Range("D2").Select

ActiveCell.FormulaR1C1 = "LC"

Next I


End Sub


Kaushik
 
Opps I am sorry...


Here it is:


Sub SheetsLoop()


Dim sh As Worksheet


For Each sh In ActiveWorkbook.Worksheets


sh.Range("D2").FormulaR1C1 = "LC"


Next sh

End Sub
 
Hi Jay ,


Try this :

[pre]
Code:
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Worksheets
If sh.Visible = xlSheetVisible Then
sh.Range("D2").FormulaR1C1 = "LC"
End If
Next sh
[/pre]
Narayan
 
Hi

To write only in visibl worksheets

[pre]
Code:
Dim Sh As Worksheet

For Each Sh In ThisWorkbook.Worksheets
If Sh.Visible Then Sh.Range("D2").Value = "LC"
Next Sh
[/pre]
 
Back
Top