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
 

Some videos you may like

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
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.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,216
Office Version
  1. 365
Platform
  1. Windows
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
 

Wookie

Board Regular
Joined
Mar 4, 2003
Messages
220
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.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,216
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

Which code are you referring to?

If it's what I posted just replace all the code you posted with what I posted.
 

jakeb3482

Board Regular
Joined
Mar 6, 2006
Messages
74
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
 

Watch MrExcel Video

Forum statistics

Threads
1,122,232
Messages
5,594,962
Members
413,954
Latest member
mrsandy

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
Top