ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Creating Loop to Paste Array (https://www.excelbanter.com/excel-programming/349492-creating-loop-paste-array.html)

Nate

Creating Loop to Paste Array
 
I currently have a macro that copy pastes a formula based on a predetermined
cell range. Is there a way to create a loop that will find cells that have
values in Col B and Col C and paste the formula in Col N.

Macro Example: (Replace "=Range("N2:N100)) with loop.

ActiveCell.FormulaR1C1 = _
"=IF(RC13="""","""",SUMIF(R2C2:R500C2,R2C13:R100C1 3,R2C3:R500C3))"
Range("N2").Select
Selection.AutoFill Destination:=Range("N2:N100"), Type:=xlFillDefault
Range("N2:N100").Select
ActiveWindow.ScrollRow = 1

Thanks


Dave Peterson

Creating Loop to Paste Array
 
dim myCell as range
with activesheet
for each mycell in .range("n2:n100")
if isempty(.cells(mycell.row,"B")) _
and isempty(.cells(mycell.row,"C")) then
'both empty, do nothing
else
mycell.formular1c1 = "yourformulahere"
end if
next mycell
end with

===
I wasn't sure if both B and C had to be empty or just one (or the other).

Change that AND to Or if you want.

Nate wrote:

I currently have a macro that copy pastes a formula based on a predetermined
cell range. Is there a way to create a loop that will find cells that have
values in Col B and Col C and paste the formula in Col N.

Macro Example: (Replace "=Range("N2:N100)) with loop.

ActiveCell.FormulaR1C1 = _
"=IF(RC13="""","""",SUMIF(R2C2:R500C2,R2C13:R100C1 3,R2C3:R500C3))"
Range("N2").Select
Selection.AutoFill Destination:=Range("N2:N100"), Type:=xlFillDefault
Range("N2:N100").Select
ActiveWindow.ScrollRow = 1

Thanks


--

Dave Peterson


All times are GMT +1. The time now is 01:22 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com