Assistance setting up a "last row" macro

londa_vba

Board Regular
Joined
May 11, 2023
Messages
61
Office Version
  1. 365
Platform
  1. Windows
Hello
I found a formula that correctly identifies my last row with value results. I used the record macro feature to convert it to vba code. Now I need help piecing it together.
I am trying to identify the last row with value results and then add the text "AL" to the cell directly beneath it.

the formula that worked for me is =LOOKUP(2,1/((C:C)<>""),ROW(C:C))
when converted to vba, I got
VBA Code:
Formula2R1C1 = "=LOOKUP(2,1/((C[-3])<>""""),ROW(C[-3]))"

That's as far as I have been able to take myself...
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
If you simply want to add the text "AL" under the last cell in column C with data, use this one line of code instead:
VBA Code:
Cells(Rows.Count, "C").End(xlUp).Offset(1, 0).Value = "AL"
 
Upvote 0
If you simply want to add the text "AL" under the last cell in column C with data, use this one line of code instead:
VBA Code:
Cells(Rows.Count, "C").End(xlUp).Offset(1, 0).Value = "AL"
Hi Joe,
Your code added the text into row 97. My formula indicates the last row is 43 which is the last row I want it to identify. I am not sure if that is because I am using formulas within the cell and have copied and pasted data all over this sheet.
 
Upvote 0
Ah, so the other cells really are not blank - they have formulas that are not returning any values.
Try this instead:
VBA Code:
Dim lr as Long
lr = Columns("C").Find("*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows, LookIn:=xlValues).Row
Range("C" & lr + 1).Value = "AL"
 
Upvote 1
Solution
Ah, so the other cells really are not blank - they have formulas that are not returning any values.
Try this instead:
VBA Code:
Dim lr as Long
lr = Columns("C").Find("*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows, LookIn:=xlValues).Row
Range("C" & lr + 1).Value = "AL"
This worked perfect. This is so exciting! Thank you so much.
 
Upvote 0
You are welcome.
Glad I was able to help!
 
Upvote 0
Ah, so the other cells really are not blank - they have formulas that are not returning any values.
Try this instead:
VBA Code:
Dim lr as Long
lr = Columns("C").Find("*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows, LookIn:=xlValues).Row
Range("C" & lr + 1).Value = "AL"
If I needed to take this code one step further and have the value = to "AL" PLUS the value in the cell two columns to the left (column A) of whatever that last row is. How would I achieve that?
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,956
Members
449,096
Latest member
Anshu121

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