ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Operate on each cell in range. (https://www.excelbanter.com/excel-programming/429232-operate-each-cell-range.html)

Fred Holmes

Operate on each cell in range.
 
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

Susan

Operate on each cell in range.
 
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



On Jun 1, 1:11*pm, Fred Holmes wrote:
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



Patrick Molloy

Operate on each cell in range.
 
dim cell as range
for each cell in selection.cells
cell.Formula = "=" & Cell.Value * 2 & "*(QTR/4)"

next


"Fred Holmes" wrote in message
...
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



Jim Thomlinson

Operate on each cell in range.
 
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

--
HTH...

Jim Thomlinson


"Fred Holmes" wrote:

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


Susan

Operate on each cell in range.
 
actually, on 2nd thought, you should probably change this:
call Adjust_Formula

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

susan


On Jun 1, 1:34*pm, Susan wrote:
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

On Jun 1, 1:11*pm, Fred Holmes wrote:



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- Hide quoted text -


- Show quoted text -



Fred Holmes

Operate on each cell in range.
 
Many thanks to all who posted suggestions. The three lines of code
below are exactly what I needed.

Fred Holmes

On Mon, 1 Jun 2009 18:38:56 +0100, "Patrick Molloy"
wrote:

dim cell as range
for each cell in selection.cells
. . .
next



All times are GMT +1. The time now is 07:45 AM.

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