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: 113
Default Looping code in Excel macro

Hi to all,
Would appreciate assistance to do a loop for step2 below starting from
the last row (last record row 4993) up the the first record.
(My code is for 3 records only)

A1:AU4993=StockBase
A2:A4993=StockIndex
A2:AU4993 has 199 records of 26 rows each
The 1st row cols R:AU has the balance Brought Forward
The 26th row cols R:AU has the closing balance

Sub StockCarryForward()
'
' StockCarryForward Macro
' Macro recorded 2/24/2005 by RobertR
'

'
With Application
.Calculation = xlManual
.MaxChange = 0.001
.CalculateBeforeSave = False
End With
ActiveWorkbook.PrecisionAsDisplayed = False
For Each cell_in_loop In Range("HIROWS1")
If cell_in_loop.Value = 0 Then
With cell_in_loop
.EntireRow.Hidden = True
End With
Range("R4993:AU4993").Select
Selection.Copy
Range("R4968").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Range("R4967:AU4967").Select
Application.CutCopyMode = False
Selection.Copy
Range("R4942").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Range("R4941:AU4941").Select
Application.CutCopyMode = False
Selection.Copy
Range("R4916").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.Goto Reference:="HIROWS10"
Selection.EntireRow.Hidden = False
Application.Goto Reference:="StockIndex"
Application.CutCopyMode = False
Selection.ClearContents
End If
Next
End Sub

The macro code does the following
1.hides rows 2 to 25 for each record (0 in HIROWS10)
2.copiespaste specialvalues from row 26 cols R:AU
to row 1 cols R:AU (ie just the row above)
3.unhides all hidden rows
4.deletes Index numbers in A2:A4993 (which give various
values to R:AU)

Thank you and my apologies for length.
--
RobertR
 
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
Excel Macro Looping Helps Jurassien Excel Discussion (Misc queries) 9 February 10th 07 12:44 AM
stopping code from looping tjb Excel Worksheet Functions 3 December 7th 05 02:02 AM
Looping macros using VB code accessuser1308 Excel Discussion (Misc queries) 2 March 9th 05 11:11 PM
Code looping when it should not Todd Huttenstine Excel Programming 3 May 13th 04 09:37 PM
VBA code for looping through open workbooks and worksheets Jamie Martin[_2_] Excel Programming 1 July 24th 03 06:44 PM


All times are GMT +1. The time now is 02:09 PM.

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"