How do I find the last row of data and then use that as a variable

L

Lynn Bales

I've been concatenate two columns together and using a defined range, but
when I do this I always wind up with either not enough rows, or to many rows.
I'd like to know how to find the last row of data and then use that in a
macro to only concatenate what I have, is this possible?
 
D

dominicb

Good afternoon Lynn Bales


The macro below will find the last row of column a and the last row o
column b, concatenate the two strings in the cell and put the answer i
cell C1.

Sub Test()
a = Application.WorksheetFunction.CountA(Range("A:A"))
b = Cells(a, 1).Value
c = Application.WorksheetFunction.CountA(Range("B:B"))
d = Cells(c, 2).Value
Range("C1").Value = b & d
End Sub

HTH

Dominic
 
D

Duke Carey

If you are trying to find the last used row in a column, use something like
this

Dim rng As Range
Set rng = Range("a65536").End(xlUp)

which will set rng to the very last used cell in col A (assuming you don't
have data all the way down to the last row)
 

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