Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default Looping thru cells in a named range

Hi All,

I have a named range of non-adjacent cells and want to perform the following
actions on each of the cells in that range.

Selection.Copy
Selection.PasteSpecial Paste:=xlValues
ActiveCell.Formula = "=" & ActiveCell.Text

Can anybody tell me / provide the code to do it ?

All help greatly appreciated.

Regards

Michael Beckinsale


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Looping thru cells in a named range

Hi

This will loop through all the cells in a named range and
copy the value and add = at the begining. If you just
want the copy the value of the cell the remove the "=" &
from the code.

Sub copyCellsInNamedRange()
Dim rng As Range

For Each rng In Sheets(1).Range("test")
rng.Formula = "=" & rng.Text
Next
'clean up
Application.CutCopyMode = False
Set rng = Nothing
End Sub


-----Original Message-----
Hi All,

I have a named range of non-adjacent cells and want to

perform the following
actions on each of the cells in that range.

Selection.Copy
Selection.PasteSpecial Paste:=xlValues
ActiveCell.Formula = "=" & ActiveCell.Text

Can anybody tell me / provide the code to do it ?

All help greatly appreciated.

Regards

Michael Beckinsale


.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Looping thru cells in a named range

Michael,

I assume you are trying to force Excel to display some
information in a specific way, hence using
the .formula= "=" & ActiveCell.Text?

You could try something like
for each cell in NamedRange
cell.Copy
cell.PasteSpecial Paste:=xlValues
cell.Formula = "=" & cell.Text
next cell

you should be able to use just the cell.Formula = line
which will streamline it a little.

cell and NamedRange are dim'd as Range objects
and Named range is set with:
Set NamedRange = Sheets("Sheet Name").Range("Range Name")

-----Original Message-----
Hi All,

I have a named range of non-adjacent cells and want to

perform the following
actions on each of the cells in that range.

Selection.Copy
Selection.PasteSpecial Paste:=xlValues
ActiveCell.Formula = "=" & ActiveCell.Text

Can anybody tell me / provide the code to do it ?

All help greatly appreciated.

Regards

Michael Beckinsale


.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Looping thru cells in a named range

the two solutions suggested so far echoed your construct, but will probably
either raise an error when they do the formula part or produce a formula
that displays an error. I believe you need a construct like:

ActiveCell = "=""" & ActiveCell.Text & """"

so your formula ends up like
="$100.00"

But I guess it would depend on what is in the cell and how it displays.

--
Regards,
Tom Ogilvy


"Michael Beckinsale" wrote in message
...
Hi All,

I have a named range of non-adjacent cells and want to perform the

following
actions on each of the cells in that range.

Selection.Copy
Selection.PasteSpecial Paste:=xlValues
ActiveCell.Formula = "=" & ActiveCell.Text

Can anybody tell me / provide the code to do it ?

All help greatly appreciated.

Regards

Michael Beckinsale




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Looping thru cells in a named range

Since you said they work just fine, I assume you are using this with numbers
in a form of Precision as Displayed.

--
Regards,
Tom Ogilvy


"Tom Ogilvy" wrote in message
...
the two solutions suggested so far echoed your construct, but will

probably
either raise an error when they do the formula part or produce a formula
that displays an error. I believe you need a construct like:

ActiveCell = "=""" & ActiveCell.Text & """"

so your formula ends up like
="$100.00"

But I guess it would depend on what is in the cell and how it displays.

--
Regards,
Tom Ogilvy


"Michael Beckinsale" wrote in message
...
Hi All,

I have a named range of non-adjacent cells and want to perform the

following
actions on each of the cells in that range.

Selection.Copy
Selection.PasteSpecial Paste:=xlValues
ActiveCell.Formula = "=" & ActiveCell.Text

Can anybody tell me / provide the code to do it ?

All help greatly appreciated.

Regards

Michael Beckinsale






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
Looping thru a range of cells COBOL Dinosaur New Users to Excel 9 June 2nd 07 03:41 AM
Copy cells from named range Melissa Excel Discussion (Misc queries) 2 January 19th 07 08:27 PM
Array as a "named range" - formula ok in cells, but error as "named range" tskogstrom Excel Discussion (Misc queries) 11 December 28th 06 04:44 PM
inserting a named range into new cells based on a named cell Peter S. Excel Discussion (Misc queries) 1 June 4th 06 03:53 AM
looping cells though a named range Jo[_4_] Excel Programming 1 August 20th 03 12:32 AM


All times are GMT +1. The time now is 11:01 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"