PDA

View Full Version : Looping a Macro



Techie007
11-03-2010, 09:31 AM
I have a table that has products along rows, and monthly sales figures along the columns for each month.
Product Jan Feb March April ....
A 20 23 14 41
B .....

I need to rank the products (monthly and YTD) acc. to their sales. I recorded a macro for the month of Jan but i need the macro to run for all the months... but this could be from Jan-April, or Jan - Oct etc.. depending on when I check this .. either in May or in Nov....

so i want VBA to dynamically rank till the last column .. how do i move across columns and run the macro till the last column ...

pls help ! TIA

GTO
11-03-2010, 09:57 AM
Hi there,

I'm about signing out, but thought to suggest that you might want to attach a small workbook. Show the "before" on one sheet and the "after" on another.

Have a great day :-)

Mark

Paul_Hossler
11-04-2010, 12:16 PM
I usually do something like this


Option Explicit
Sub demo()
Dim rData As Range, rCol As Range

Set rData = ActiveSheet.Cells(1, 1).CurrentRegion

For Each rCol In rData.Columns

If rCol.Column <> rData.Columns(1).Column Then
'your logic goes here
MsgBox Application.WorksheetFunction.Sum(rCol)
End If
Next
End Sub


Paul