Travel through no of sheets in a workbook.

  • Thread starter Thread starter Raj
  • Start date Start date
R

Raj

Hi all,

I'm facing with a problem can any one help me on the issue
that i'm facing which is explained further.I'm working on an Hr report
which has 30 sheets in in and in a loop i would like to travel up till
the 25th sheet and while i'm travelling i would like to write some
data in to each sheets can any one provide me with an solution for
this problem.
 
Sub thshets()
For i = 1 To 25
Sheets(i).Cells(1, 1).Value = "Something"
Next i
End Sub
 
Well, without mroe information than that, here's a basic place to
start:

Private Sub DoSomething()
Dim w As Worksheet

For Each w In ActiveWorkbook.Sheets
'this next line stops the code from
'running after sheet 25
If w.Index > 25 Then Exit Sub
'code here to write something to
'a sheet as you're passing through.
'for example:
Range("A1").Value = w.Name
Next
End Sub

Hope that helps!

Cory
 
Well, without mroe information than that, here's a basic place to
start:

Private Sub DoSomething()
Dim w As Worksheet

For Each w In ActiveWorkbook.Sheets
'this next line stops the code from
'running after sheet 25
If w.Index > 25 Then Exit Sub
'code here to write something to
'a sheet as you're passing through.
'for example:
Range("A1").Value = w.Name
Next
End Sub

Hope that helps!

Cory




- Show quoted text -

thanks a lot for ur valuable solution
 
Well, without mroe information than that, here's a basic place to
start:

Private Sub DoSomething()
Dim w As Worksheet

For Each w In ActiveWorkbook.Sheets
'this next line stops the code from
'running after sheet 25
If w.Index > 25 Then Exit Sub
'code here to write something to
'a sheet as you're passing through.
'for example:
Range("A1").Value = w.Name
Next
End Sub

Hope that helps!

Cory




- Show quoted text -

I'm glad it helped. Have a great week.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top