Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
I have a column in a worksheet which has a list of 3 digit numbers. I want to
change the 3 digits to become 4 digits, the new fourth digit has to be a leading zero, i.e 355 to become 0355. I prefer the format of the digits to be a number but a text format would not be a problem. The length of the digits in the column are not static. i.e one month there may be 200 rows of data the next might be 300 and I would want the macro to cater for this variation. Thanks -- James |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
James,
A macro simply isn't necessary, select the column and apply a custom format of 0000 that's four zeroes -- Mike When competing hypotheses are otherwise equal, adopt the hypothesis that introduces the fewest assumptions while still sufficiently answering the question. "James C" wrote: I have a column in a worksheet which has a list of 3 digit numbers. I want to change the 3 digits to become 4 digits, the new fourth digit has to be a leading zero, i.e 355 to become 0355. I prefer the format of the digits to be a number but a text format would not be a problem. The length of the digits in the column are not static. i.e one month there may be 200 rows of data the next might be 300 and I would want the macro to cater for this variation. Thanks -- James |
#3
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Click on any cell in the column and run:
Sub MakeLeadingZero() Dim ic As Long, n As Long, i As Long Dim z As String ic = ActiveCell.Column n = Cells(Rows.Count, ic).End(xlUp).Row z = "0" For i = 1 To n With Cells(i, ic) v = .Value .NumberFormat = "@" .Value = z & v End With Next End Sub -- Gary''s Student - gsnu200909 "James C" wrote: I have a column in a worksheet which has a list of 3 digit numbers. I want to change the 3 digits to become 4 digits, the new fourth digit has to be a leading zero, i.e 355 to become 0355. I prefer the format of the digits to be a number but a text format would not be a problem. The length of the digits in the column are not static. i.e one month there may be 200 rows of data the next might be 300 and I would want the macro to cater for this variation. Thanks -- James |
#4
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Mike thanks sometimes it is so easy to look over the simple way out.
Thanks -- James "Mike H" wrote: James, A macro simply isn't necessary, select the column and apply a custom format of 0000 that's four zeroes -- Mike When competing hypotheses are otherwise equal, adopt the hypothesis that introduces the fewest assumptions while still sufficiently answering the question. "James C" wrote: I have a column in a worksheet which has a list of 3 digit numbers. I want to change the 3 digits to become 4 digits, the new fourth digit has to be a leading zero, i.e 355 to become 0355. I prefer the format of the digits to be a number but a text format would not be a problem. The length of the digits in the column are not static. i.e one month there may be 200 rows of data the next might be 300 and I would want the macro to cater for this variation. Thanks -- James |
#5
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Gary thanks for highlighting this in a VBA statement.
-- James "Gary''s Student" wrote: Click on any cell in the column and run: Sub MakeLeadingZero() Dim ic As Long, n As Long, i As Long Dim z As String ic = ActiveCell.Column n = Cells(Rows.Count, ic).End(xlUp).Row z = "0" For i = 1 To n With Cells(i, ic) v = .Value .NumberFormat = "@" .Value = z & v End With Next End Sub -- Gary''s Student - gsnu200909 "James C" wrote: I have a column in a worksheet which has a list of 3 digit numbers. I want to change the 3 digits to become 4 digits, the new fourth digit has to be a leading zero, i.e 355 to become 0355. I prefer the format of the digits to be a number but a text format would not be a problem. The length of the digits in the column are not static. i.e one month there may be 200 rows of data the next might be 300 and I would want the macro to cater for this variation. Thanks -- James |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How do I change the row/column format in a macro to beyond letters? | Excel Discussion (Misc queries) | |||
Launch macro when drop-down contents change... | Excel Discussion (Misc queries) | |||
Excel Macro to Insert the contents of one column to other | Excel Discussion (Misc queries) | |||
macro to change multiple values in a column | Excel Discussion (Misc queries) | |||
Macro to remove contents of cell and move all other contents up one row | Excel Discussion (Misc queries) |