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 |
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 |
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 |
All times are GMT +1. The time now is 08:21 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com