Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
format cell custom Number format | Excel Worksheet Functions | |||
Format Cell/Number | Excel Discussion (Misc queries) | |||
Format a cell with a custom number format | Excel Worksheet Functions | |||
Number format based on number format of another cell in another workbook | Excel Programming | |||
Conditional format cell ranges with loop? | Excel Programming |