VBA - last cell in column

Wookie

Board Regular
Joined
Mar 4, 2003
Messages
220
What I would like is a bit of code that would look down Column A in my worksheets (Debit by Co&Vend from the code below) and give the answer of the last cell in that column with values in it. The answer to the first part would then be used to replace Selection.AutoFill Destination:=Range("B2:D5000")
with Selection.AutoFill Destination:=Range("B2:whatever last cell is").

At the moment the code i have is not looking for the last cell as i have chosen a range that is big enough to make sure i dont miss entries.

Sheets("Debit by Co&Vend").Select
Range("B2:D2").Select
Application.CutCopyMode = False
Selection.AutoFill Destination:=Range("B2:D5000")
Range("B2:D5000").Select
Columns("A:D").Select
Selection.Copy
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Hi

Something like:

Code:
Dim lngLastRow As Long
 
lngLastRow = Cells(Rows.Count,"A").End(xlUp).Row

Then you have your last row, and can use it to define your range.
 
Upvote 0
Something like this?
Code:
Dim LastRow As Long
With Sheets("Debit by Co&Vend")
    LastRow = .Range("A" & Rows.Count).End(xlUp.Row)
    .Range("B2:D2").Copy .Range("B2:D2").Resize(LastRow - 1)
End With
 
Upvote 0
Sorry for my ignorance but how do i go about putting this into the code, what should i take out of what i posted etc.
 
Upvote 0
Which code are you referring to?

If it's what I posted just replace all the code you posted with what I posted.
 
Upvote 0
use this below:

Function find_in_col(search_term, col) As Integer
counter = 0
Do
counter = counter + 1
Loop While Cells(counter, col) <> search_term
find_in_col = counter

End Function

search term will be ""
col will be the column you are working in.

so rowx = find_in_col("",1)
this will give you the row number of the last column
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,427
Members
448,961
Latest member
nzskater

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top