How to Count Columns

G

gatarossi

Dear all,

I need to do a code until the last column with data in one line, but
in this code belown, if there is a column with no data, the code
doesn't work very well, because it doesn't count this column.

count = 1
col = Application.CountA(Worksheets("resume").Rows(4))

Do Until count = col

A B C D E F G H I ...
1 2 3 4 5 6 7

With this variant, the code will run until the number 7 because col is
equal 7, but I need that the code run until 9.

How can I solve this problem? I have different number of columns!

Thanks in advance!!!

André.
 
D

Don Guillett

do until count=cells(4,columns.count).end(xltoleft).column

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(e-mail address removed)
Dear all,

I need to do a code until the last column with data in one line, but
in this code belown, if there is a column with no data, the code
doesn't work very well, because it doesn't count this column.

count = 1
col = Application.CountA(Worksheets("resume").Rows(4))

Do Until count = col

A B C D E F G H I ...
1 2 3 4 5 6 7

With this variant, the code will run until the number 7 because col is
equal 7, but I need that the code run until 9.

How can I solve this problem? I have different number of columns!

Thanks in advance!!!

André.
 
D

Dave Peterson

Maybe...

dim LastCol as long
dim myCount as long 'I wouldn't use a variable named Count

with worksheets("resume")
LastCol = .cells(4,.columns.count).end(xltoleft).column
'rest of code here
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top