Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 112
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default 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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default 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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default 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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default 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 -




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 112
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Operate the active Excel Window with VB6 NTorch Excel Programming 1 July 27th 06 03:47 AM
The formula to operate in shhet2 please. Steved Excel Worksheet Functions 4 June 11th 05 10:56 PM
Function to operate on ink linked to cell Alan T Excel Worksheet Functions 0 November 20th 04 10:03 PM
tell excel to operate in hexadecimal ( base 16)? Caroline Jones - CTI Excel Worksheet Functions 1 November 11th 04 03:04 PM
Can Excel operate as Database? ND Excel Programming 1 September 18th 03 05:06 PM


All times are GMT +1. The time now is 08:17 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"