-
Looping a Macro
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
-
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
-
I usually do something like this
[vba]
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
[/vba]
Paul
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules