VBA Help - Modify a LastRow Lookup line of code - Excel 2016

Johnny Thunder

Well-known Member
Joined
Apr 9, 2010
Messages
693
Office Version
  1. 2016
Platform
  1. MacOS
Hello All,

I have a piece of code that I need to modify since it works so well, it essentially is a Last Row Lookup (Column Based) and defines the last row with an actual formula result.


What I need: I have a variable to replace the column letter "ColumnL" that I need to update the line of code but it doesn't seem to work with different variations that I have tried.

Line: cSht.[match(2,1/(AP:AP<>0))]

cSht = my Variable Sheet

Any help is appreciated.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
It's not clear what you want to do.
If you want to find the last row number with data in column AP :
Code:
LR=Cells(Rows.count,"AP").End(xlUp).Row
 
Upvote 0
I thought my post was extremely clear. I am looking to modify my already working code to replace the manual "AP" column designation to my dynamic variable "ColumnL"

Also, the code you posted results in 1, there is over 1000 rows of data and the last cell that resulted in a value ends at 617. My line of code works great, I just don't know how to modify it to include my variable instead of hardcoding the range like "AP:AP".

Thank you for trying though. This is one of the final pieces of my code and I am done.
 
Upvote 0
Maybe
Code:
Dim Clmn As String
Clmn = "AP:AP"
Debug.Print csht.Evaluate("match(2,1/(" & Clmn & "<>0))")
But it's a very slow way of doing it.
 
Upvote 0
Woohoo! That is exactly what I needed!

May I ask, whats the line about evaluate? And what was the need for the [ ] brackets used in the original version of the formula? I found it on this site a few days back and wasn't really sure how it worked but it works well.
 
Upvote 0
You're welcome & thanks for the feedback
The [] is a "shorthand" way of using Evaluate, but I don't think you can use it with variables.
 
Upvote 0
I thought my post was extremely clear. I am looking to modify my already working code to replace the manual "AP" column designation to my dynamic variable "ColumnL"

Also, the code you posted results in 1, there is over 1000 rows of data and the last cell that resulted in a value ends at 617. My line of code works great, I just don't know how to modify it to include my variable instead of hardcoding the range like "AP:AP".

Thank you for trying though. This is one of the final pieces of my code and I am done.
If the code I posted assigns a value of 1 to LR, either there is no data in column AP or data in AP1 only.
Although your code is now working, it's better to avoid using worksheet formulas in code unnecessarily.
This is better/standard :
Code:
Dim Clmn As String, LR#
Clmn = "AP:AP"
LR = Cells(Rows.Count, Clmn).End(xlUp).Row
There are other ways which avoid using a worksheet function :
https://www.google.com/search?q=exc....1.69i57j0.77321j0j8&sourceid=chrome&ie=UTF-8
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

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