Consulting

Results 1 to 4 of 4

Thread: VBA run code if 3 rows and different code if 7

  1. #1

    VBA run code if 3 rows and different code if 7

    Hi all,

    I've come across an issue i'm having with a tool i've been creating.

    What's the best way to have it run one code if there are 3 columns of data and another if there's say, 7?

    At the moment i'm always using 3 columns so it runs pretty spot on, but now i'm seeing that a second lot of data i want to be able to run in it could have 7 columns.

    It's worth pointing out that it will never combine the 2 different data sets so it will always be one or the other, never both.

    Cheers for your help guys...

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    What's the best way to have it run one code if there are 3 columns of data and another if there's say, 7?
    One macro named Columns3 and another named Columns7.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    Title says 'Rows' but post implies 'Columns' -- I'll assume you really meant 'Columns'

    Make is a smart macro that determines the number of columns and acts accordingly

    If Activesheet.Range("A1").CurrentRegion.Columns.Count = 3 Then
    
    .........
    
    ElseIf Activesheet.Range("A1").CurrentRegion.Columns.Count = 7 Then
    
    
    ......
    
    Else
    
    Msgbox "Cannot handle " & Activesheet.Range("A1").CurrentRegion.Columns.Count
    
    
    EndIF
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  4. #4
    Paul,

    Many thanks.

    rows/colums my brains having a slight meltdown lately. everything seems to mean the same to me at the moment!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •