PDA

View Full Version : [SOLVED] VBA run code if 3 rows and different code if 7



MattehWoo
08-22-2016, 02:21 AM
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...

SamT
08-22-2016, 07:32 AM
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.

Paul_Hossler
08-22-2016, 06:29 PM
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

MattehWoo
08-24-2016, 12:07 AM
Paul,

Many thanks.

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