find last value in a column and clear contents up VBA

pook_666

Board Regular
Joined
Aug 16, 2018
Messages
94
Hi magicians,

I have the below code that finds the last cell in L and clears its contents.

VBA Code:
Range("L" & Cells(Rows.Count, "L").End(xlUp).Row).ClearContents

What I want to do is find the last cell in L and clear contents upwards to the next gap.

For example, on the below, I want to clear contents 14:18 only. However, the values can be changeable and not always in the cells as listed below. Hence why I need to find the last active cell and then looking upwards (in the below case to 14) and only clearing that last batch of values.

1618986598182.png


I hope I've explained myself clearly enough - please let me know if you need any other info! Thanks!
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
If the cells are truly blank you can just do something like

VBA Code:
Dim myRng As Range
Set myRng = Range("L" & Cells(Rows.Count, "L").End(xlUp).Row)
Range(myRng.End(xlUp), myRng).ClearContents
 
Upvote 0
Solution
Thanks for the help @MARK858, however, this clears the top section instead of the last section of values. E.g using my picture snapshot above, this deletes 1:4 instead of 14:18?
 
Upvote 0
Doesn't for me, it clears the bottom section. Are you sure that your "blank" cells are actually blank i.e. no formulas, no spaces etc.

What does the formula
Excel Formula:
=ISBLANK(L13)
give you?
 
Upvote 0
Aha worked it out....I put the set myRng in the wrong spot (put it at the beginning of the long VBA I have instead of right before the clear contents line). All working now - thanks a lot for your help!
 
Upvote 0
Happy you got it working (even though it shouldn't make any difference the "Set" being at the start of the code unless you have something else you haven't stated affecting it between it and the ClearContents [as long as you have the lines in the same order])
 
Upvote 0

Forum statistics

Threads
1,214,867
Messages
6,122,002
Members
449,059
Latest member
mtsheetz

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