Clear range of data

redspanna

Well-known Member
Joined
Jul 27, 2005
Messages
1,604
Office Version
  1. 365
Platform
  1. Windows
Hi all

Question 1:

Can anybody tell me how I can get vb to clear the contents of cells Q7 through to last populated cell in column Q up 5

So if last populated cell in column Q is cell Q90, I want Q7:Q85 cleared

Question 2:

place the formula
Code:
=SUM(E7+H7-K7)/C7
into cell Q7 then copy down to last populated cell in column Q but up 5
so, again if last populated cell in column Q is cell Q90, I want formula added to Q7:Q85 only!

many thanks
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi, try this:

Code:
sub trythis()

lastrow = cells(rows.count,17).end(xlup).row
range([Q7],cells(lastrow-5,17)).formular1c1 = "=(RC[-12]+RC[-9]-RC[-6])/RC[-14]"

end sub

You don't need to clear the contents before entering the formula, and you don't need to use SUM in your formula. "=(E7+H7-K7)/C7" is sufficient.
 
Upvote 0
For 1 try

Code:
Dim LR As Long
LR = Range("Q" & Rows.Count).End(xlUp).Row
Range("Q7:Q" & LR - 5).ClearContents

For 2

Code:
Dim LR As Long
LR = Range("Q" & Rows.Count).End(xlUp).Row
Range("Q7:Q" & LR - 5).Formula = "=SUM(E7+H7-K7)/C7"
 
Upvote 0

Forum statistics

Threads
1,224,503
Messages
6,179,134
Members
452,890
Latest member
Nikhil Ramesh

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