LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default Looping within a loop

Hi,
I want to run each store, within each period and put a line in a summary
sheet with each store/period, but I've got it wrong in the code. Can someone
help?
--
Thanks,
PTweety
Sub runScores()

' RunScores Macro

Dim wksSummary As Worksheet
Dim wksScroll As Worksheet
Dim perCell As Range
Dim perLoop As Range
Dim strCell As RecentFile
Dim strLoop As Range
Dim wksTemplate As Worksheet
Dim strLocation As String

Set wksScroll = Sheets("scroll list")
Set wksTemplate = Sheets("Template")
Set wksSummary = Sheets("Summary")

'clear the old "summary" page
With wksSummary
.Range("a7", .Range("a7").End(xlDown)).EntireRow.ClearContents
End With


'Select the list of periods (range) on "scroll list" sheet
With wksScroll
Set perLoop = .Range("b1", .Range("b1").End(xlDown))
End With

'Loop through each period
For Each perCell In perLoop
With wksTemplate
.Range("g6").Value = perCell
End With

'Select the list of stores (range) on "scroll list" sheet
With wksScroll
Set strLoop = .Range("a1", .Range("a1").End(xlDown))
End With

'Loop through each location within each period
For Each strCell In strLoop
With wksTemplate
.Range("b1").Value = strCell
.Calculate
strLocation = .Range("B1").Value
End With

'fill in the next line of the "summary" sheet
CopyToNext wksSummary

Next strCell
Next perCell

wksSummary.Outline.ShowLevels RowLevels:=1, ColumnLevels:=1
Range("a1").Select

End Sub


Sub CopyToNext(wks As Worksheet)

Dim rngfill As Range

'MsgBox wks.Name

With wks
..Outline.ShowLevels RowLevels:=2, ColumnLevels:=2
..Calculate
Set rngfill = Nothing
Set rngfill = .Range("A" & .Rows.Count).End(xlUp)
Set rngfill = rngfill.Offset(1, 0)

Rows("3:3").Copy
rngfill.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

rngfill.PasteSpecial Paste:=xlFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

Application.CutCopyMode = False


End With

End Sub

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Do Until€¦Loop Question for the Excel-Looping-Experts ryguy7272 Excel Programming 7 February 20th 07 06:29 AM
Do Loop Won't Stop Looping Lost in Alabama Excel Programming 13 February 23rd 06 12:26 AM
Looping SQL query w/changing parameters in each loop not working Laurin[_3_] Excel Programming 7 December 9th 05 03:35 PM
Looping a loop? John Excel Programming 3 August 15th 05 02:19 PM
Looping procedure calls userform; how to exit loop (via userform button)? KR Excel Programming 6 July 27th 05 12:57 PM


All times are GMT +1. The time now is 06:36 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"