Operate on each cell in range.

  • Thread starter Thread starter Fred Holmes
  • Start date Start date
F

Fred Holmes

How do I put wrapper code around the below, so that I can select a
range of "many" cells and have the code execute on each cell in turn?

For each cell in selected range (selection) . . .

Sub Adjust_Formula()
ActiveCell.Formula = "=" & ActiveCell.Value * 2 & "*(QTR/4)"
End Sub

The formula works fine on a single cell.

Many thanks,

Fred Holmes
 
Sub do_all()

dim MyRange as range
dim c as range

'adjust myrange to suit
set MyRange = worksheet.range("a1:b15")

for each c in MyRange
call Adjust_Formula
next c

End Sub

that should do it!
(somebody else will probably have a simpler way of doing it,
but..........)
:)
susan
 
dim cell as range
for each cell in selection.cells
cell.Formula = "=" & Cell.Value * 2 & "*(QTR/4)"

next
 
select a group of cells and run the following...

Sub Adjust_Formula()
dim rng as range

for each rng in selection
rng.Formula = "=" & rng.Value * 2 & "*(QTR/4)"
next rng
End Sub
 
actually, on 2nd thought, you should probably change this:
call Adjust_Formula

to this:
c.Formula = "=" & c.Value * 2 & "*(QTR/4)"

susan
 
Many thanks to all who posted suggestions. The three lines of code
below are exactly what I needed.

Fred Holmes
 
Back
Top