Need code that clear specific contents

wroze27

New Member
Joined
Apr 23, 2021
Messages
31
Office Version
  1. 2019
Platform
  1. Windows
For a project I'm doing at work I need to be able to clear certain cells in the last line of a table. I want to clear the cells in columns B,C,J,K,L,M,N,O,P while leaving the formulas in the other in place.
Currently I have this which only clears the whole row:
Sub Clear()

Dim lr As Long
lr = Cells(Rows.Count, "A").End(xlUp).Row
Rows(lr).ClearContents

End Sub

Thanks for any advice
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Welcome to the Board!

Here is one way:
VBA Code:
Sub MyClear()

    Dim lr As Long
    Dim rng1 As Range
    Dim rng2 As Range
    
    lr = Cells(Rows.Count, "A").End(xlUp).Row
    
    Set rng1 = Intersect(Rows(lr), Range("B:C"))
    Set rng2 = Intersect(Rows(lr), Range("J:P"))
    rng1.ClearContents
    rng2.ClearContents

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,213,549
Messages
6,114,264
Members
448,558
Latest member
aivin

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