printing formula to a particular Count

R

robs_drunk

How do i set this formula so that rng2 only prints as many fields as
the count of rng1?

Set rng1 = Sheets("Imported Budget Data").Range("A2:BX2")
For Each cell In rng1
If cell.Value > 0 Then
Count = Count + 1
End If
Next cell
Set rng2 = Sheets("SandBox").Range("B6:B100")
rng2.Formula = "=IF(Home!$B$5='Imported Budget Data'!BX2,'Imported
Budget Data'!S2,)"
 
B

Bob Phillips

What exactly do you mean by print, formulae don't print.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
R

robs_drunk

By print I mean that the formula is written into cells B6:B100 but i
want the formula to be written in to only as many cells as that where
counted in rng1.
 
B

Bob Phillips

OK, does this do it

Set rng1 = Sheets("Imported Budget Data").Range("A2:BX2")
For Each cell In rng1
If cell.Value > 0 Then
Count = Count + 1
End If
Next cell
Set rng2 = Sheets("SandBox").Range("B6:B" & Count + 6)
rng2.Formula = "=IF(Home!$B$5='Imported Budget Data'!BX2,'Imported
Budget Data'!S2,)"


BTW, best to avoid variable names like Count, it is a property of
collections so may confuse or even fail in worst cases.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top