How to get last row variable to update

LtCmdrData

Board Regular
Joined
Jan 24, 2018
Messages
58
Office Version
  1. 365
Platform
  1. Windows
I'm still trying to learn VBA so I hope someone can help me please. I have some rows of data that I need to clean up. I set a variable, lr = Cells(Rows.Count, "A").End(xlUp).Row, to determine how many rows are in my data set based on column A. First I want to delete any blank rows and then I want to filter for certain criteria and delete more rows. Since the total number of rows keeps changing, here is my dilemma: How do I get my variable (lr) to update to the new number of rows? My work around has been to declare a new variable, such as lrow, every time my data set changes. I know there must be a better way of doing this but I don't know what I don't know. I would appreciate any help and guidance someone could offer. Thank you.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Depending on your actual code, you can probably just reset the lr variable.
 
Upvote 0
How do I reset the lr variable? Or any variable? I've never done this before.
 
Upvote 0
Exactly the same way you give it a value initially.
 
Upvote 0
So it's as simple as repeating the same line of code, the DIM statement and the lr = Cells(Rows.Count, "A").End(xlUp).Row code? Wow. Does this work for most or all variables?
 
Upvote 0
Not Dim part, you declare it once, although a Dim inside a loop is ok.
 
Upvote 0
You just need to repeat this part
VBA Code:
lr = Cells(Rows.Count, "A").End(xlUp).Row
 
Upvote 0
Solution
Why make Excel reassign it multiple times to the same data type? The memory usage is miniscule but is unnecessary.

I wasn't very explicit, so that's on me. What I tried to mean was it won't throw an error in that case.
 
Upvote 0
I tried just restating the variable again and it worked. I had no idea to solutions was this simple. Thank you Fluff and thank you Gokhan Aycan for the guidance and solution.
 
Upvote 0

Forum statistics

Threads
1,214,958
Messages
6,122,475
Members
449,087
Latest member
RExcelSearch

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