Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 113
Default Looping code in Excel macro

I am truly sorry to those who have been trying to help. The code is not
working.
I am trying to correct it now. If someone can just help me with a looping
code for this portion, explained below, I wiil surely appreciate their
assitance.

It is no longer necessary to hide any rows so long as the data in Cols R:AU
is Copied and PastedSpecial Values to 25 rows higher Cols R:AU.
ie. Copy R4993:AU4993 to R4968, similarly copy R4967:AU4967 to R4942:AU4942
upto the last record R27:AU27 copy to R2:AU2.
Thank you.

RobertR (to differenciate, there is another Robert)

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 113
Default Looping code in Excel macro

I have since achieved it by by the long way, created =formulas
for all the values to be copied then CopyPasteSpecialValuesSkipBlanks
- the processes by macro. I think works much faster than looping.

RobertR
Reply
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 12:07 AM.

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

About Us

"It's about Microsoft Excel"