VBA - Clear Content till last content cell of column

rsolanki

New Member
Joined
Jul 30, 2024
Messages
6
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hello Magicians,

I am using below line of code in my VBA sub but problem is content in cell is limited but its clearing out from G2 to G100000 which i have set but i want to make sure that vba automatically determine last cell in which there is a content and clear the whole range of content (Not Formating, only content)

VBA Code:
Worksheets("sheet1").Range("G2:G100000").ClearContents

Thanks in advance
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Why bother checking while you can clear the whole column:

VBA Code:
Worksheets("sheet1").Range("G2:G" & Rows.Count).ClearContents
 
Upvote 0
but if you insist of knowing the last used cell:

VBA Code:
Sub Clr()
    lr = Worksheets("sheet1").Range("G" & Rows.Count).End(xlUp).Row
    Worksheets("sheet1").Range("G2:G" & lr).ClearContents
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,948
Messages
6,175,579
Members
452,652
Latest member
eduedu

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