Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 183
Default Number format of ranges using cell value

I have 6 named ranges (RangeX, RangeY, Etc)
I would like to format each range using a value in a cell (cell1, Cell2,
....Cell6)
For instance if cell1.value = 2 (meaning 2 decimal places)
then format of RangeX = "0.00"
I can write this separetely for each range but this is long and tedious. is
there a clever way to loop through this?
I tried but failed.
Any idea?

--
caroline
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Number format of ranges using cell value

Try..

Sub Macro()
Dim strNames As String, arrNames As Variant, intCount As Integer
Dim strCells As String, arrCells As Variant

strNames = "RangeX,RangeY,RangeZ"
strCells = "A1,A2,A3"

arrNames = Split(strNames, ",")
arrCells = Split(strCells, ",")

For intCount = 0 To UBound(arrNames)
Range(arrNames(intCount)).NumberFormat = _
"0." & String(Range(arrCells(intCount)), "0")
Next
End Sub

--
Jacob


"caroline" wrote:

I have 6 named ranges (RangeX, RangeY, Etc)
I would like to format each range using a value in a cell (cell1, Cell2,
...Cell6)
For instance if cell1.value = 2 (meaning 2 decimal places)
then format of RangeX = "0.00"
I can write this separetely for each range but this is long and tedious. is
there a clever way to loop through this?
I tried but failed.
Any idea?

--
caroline

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 183
Default Number format of ranges using cell value

Totally brilliant. Thanks

--
caroline


"Jacob Skaria" wrote:

Try..

Sub Macro()
Dim strNames As String, arrNames As Variant, intCount As Integer
Dim strCells As String, arrCells As Variant

strNames = "RangeX,RangeY,RangeZ"
strCells = "A1,A2,A3"

arrNames = Split(strNames, ",")
arrCells = Split(strCells, ",")

For intCount = 0 To UBound(arrNames)
Range(arrNames(intCount)).NumberFormat = _
"0." & String(Range(arrCells(intCount)), "0")
Next
End Sub

--
Jacob


"caroline" wrote:

I have 6 named ranges (RangeX, RangeY, Etc)
I would like to format each range using a value in a cell (cell1, Cell2,
...Cell6)
For instance if cell1.value = 2 (meaning 2 decimal places)
then format of RangeX = "0.00"
I can write this separetely for each range but this is long and tedious. is
there a clever way to loop through this?
I tried but failed.
Any idea?

--
caroline

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
format cell custom Number format Dan Excel Worksheet Functions 2 January 26th 10 05:29 PM
Format Cell/Number peyman Excel Discussion (Misc queries) 10 July 23rd 08 06:08 AM
Format a cell with a custom number format Armor Excel Worksheet Functions 4 January 29th 06 11:25 PM
Number format based on number format of another cell in another workbook Rob Excel Programming 9 January 9th 05 04:30 PM
Conditional format cell ranges with loop? welded Excel Programming 7 June 19th 04 07:54 AM


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