scarlettsr
New Member
- Joined
- Jan 24, 2009
- Messages
- 12
Hello,
I am a VBA newbie. I am trying to piece together some code to pull data from a specified range (L9 to L173-that does not change) in about 152 worksheets. I need to SKIP any worksheet in the 152 sheets that has the word "Total" in the Worksheet name (ex: Total 2121 Finance Dept). How do I write the code to actually SKIP the TOTAL sheets? Thanks for your help!
Dim WkSht As Integer
Dim R As Integer
R = 1
For WkSht = 1 To 152 'sub your number here
Dim Rng As Range
For Each Rng In Sheets(WkSht).Range("L9:L173")
If (Sheets(WkSht).Cells(Rng.Row, 1).Value Mod 100 <> 0) Then
If (Rng.Value) > 0 Then
Sheets("Summary").Select
' set all of the data
Cells(R, 1) = Sheets(WkSht).Cells(5, 2).Value ' Budget Unit from Spreadsheet
Cells(R, 2) = Sheets(WkSht).Cells(Rng.Cells.Row, 1).Value ' Expense Category
Cells(R, 3) = Year(Now) Mod 100
Cells(R, 4).Value = Rng.Value
R = R + 1
End If
End If
Next Rng
Next WkSht
I am a VBA newbie. I am trying to piece together some code to pull data from a specified range (L9 to L173-that does not change) in about 152 worksheets. I need to SKIP any worksheet in the 152 sheets that has the word "Total" in the Worksheet name (ex: Total 2121 Finance Dept). How do I write the code to actually SKIP the TOTAL sheets? Thanks for your help!
Dim WkSht As Integer
Dim R As Integer
R = 1
For WkSht = 1 To 152 'sub your number here
Dim Rng As Range
For Each Rng In Sheets(WkSht).Range("L9:L173")
If (Sheets(WkSht).Cells(Rng.Row, 1).Value Mod 100 <> 0) Then
If (Rng.Value) > 0 Then
Sheets("Summary").Select
' set all of the data
Cells(R, 1) = Sheets(WkSht).Cells(5, 2).Value ' Budget Unit from Spreadsheet
Cells(R, 2) = Sheets(WkSht).Cells(Rng.Cells.Row, 1).Value ' Expense Category
Cells(R, 3) = Year(Now) Mod 100
Cells(R, 4).Value = Rng.Value
R = R + 1
End If
End If
Next Rng
Next WkSht