Consulting

Results 1 to 3 of 3

Thread: Looping a Macro

  1. #1

    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

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    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

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    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
  •