Clear Contents for a changing range based on a cells' value

jpj31

New Member
Joined
Apr 26, 2022
Messages
14
Office Version
  1. 2016
Platform
  1. Windows
1651236769599.png

I've got another macro that is inserting a range of values into this example template and right now it's filling down the formulas from row 6. I need a code that's either going to clear the contents for A:E and L:IL of a row, if there's not a value in F:K of a row. From 5 rows above "TOTALS" in column P. Or a code that copies the formulas from N16:IL16.

I've tried the following:
Sub Paste_Formulas()
'
' Paste_Formulas Macro
Dim totalrow As Long
Dim lc As Range
Dim ws As Worksheet

Set ws = Worksheets("BUILDING CONC")
Set lc = [P:P].Find(What:="End", After:=[P19], LookIn:=xlFormulas, LookAt:=xlWhole, SearchDirection:=xlPrevious)

If Not lc Is Nothing Then totalrow = lc.Row
ws.Range("N16:IL16").Copy
ws.Range("N19:IL" & totalrow).PasteSpecial xlPasteAll

But it doesn't appear to be working. Any suggestions or help would be greatly appreciated.
 

Attachments

  • 1651236616724.png
    1651236616724.png
    15.3 KB · Views: 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
To copy the formulas, don't use copy paste. It is slow and unwieldy. Just set the formulas for the range.
VBA Code:
    ws.Range("N19:IL" & totalrow).Formula = ws.Range("N16:IL16").Formula
 
Upvote 0
Solution
To copy the formulas, don't use copy paste. It is slow and unwieldy. Just set the formulas for the range.
VBA Code:
    ws.Range("N19:IL" & totalrow).Formula = ws.Range("N16:IL16").Formula
Thank you for responding!

I had adapted it to "Filldown" and then "ClearContents" to delete formulas I didn't want. Would your method be any faster? I'm still learning.
 
Upvote 0
I would need to test it to see which is faster. Filldown is beter than copy paste anyway. Clearcontents is fast
 
Upvote 0

Forum statistics

Threads
1,215,032
Messages
6,122,772
Members
449,095
Latest member
m_smith_solihull

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