I have copied a cell using vba that is formatted as Custom "00000"
eg 07455
when I try to copy this value the active cell and concat with text, I loose the leading zero. here's the code i'm using -
ActiveCell.EntireRow.Cells(1, "B").Value = "WO-" & ws.Range("B12").Value
I've tried formatting the destination (active cell) as Custom "00000" but it I still loose the zero.
I end up with WO-7455 instead of WO-07455
Can anyone help please?
thanks Craig
Try:
ActiveCell.EntireRow.Cells(1, "B").Value = "WO-" & ws.Range("B12").Text
or (not tested)
ActiveCell.EntireRow.Cells(1, "B").Value = "WO-" & Format(ws.Range("B12").Value,"00000")
EDIT: Note that the first option will show whatever the source cell ( B12
) displays. So if the column is so narrow that the display is ##
or hidden, the result cell may not display what you expect. The second option should always work, no matter the column width of the source cell.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.