Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Format for Leading Zeros


I'm importing a report from another workbook. How can I format column A
of the destination with leading zeros in the code below? The source is
formatted as General. Thanks.


Code:
--------------------
Dim wb As Workbook
Application.ScreenUpdating = False
Set wb = Workbooks.Open("C:\FOReport.xls", True, True)
With ThisWorkbook.Worksheets("Report")
.Range("A5:F798") = ""
.Range("A5:F798").Value = wb.Worksheets("Report").Range("C7:H80").Value
End With
--------------------


--
DavidW
------------------------------------------------------------------------
DavidW's Profile: http://www.excelforum.com/member.php...o&userid=32630
View this thread: http://www.excelforum.com/showthread...hreadid=534117

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Format for Leading Zeros

There's probably a better way, but this would work....


Dim X As Integer
Dim wb As Workbook
Application.ScreenUpdating = False
Set wb = Workbooks.Open("C:\FOReport.xls", True, True)
With ThisWorkbook.Worksheets("Report")
.Range("A5:F798") = ""
.Range("A5:F798").Value =
wb.Worksheets("Report").Range("C7:H80").Value
.Range("A5:F798").NumberFormat = "@"
For X = 5 To 798
.Range("A" & X & ":A" & X).Value = Format(.Range("A" & X & ":A"
& X).Value, "00000")
.Range("B" & X & ":B" & X).Value = Format(.Range("B" & X & ":B"
& X).Value, "00000")
.Range("C" & X & ":C" & X).Value = Format(.Range("C" & X & ":C"
& X).Value, "00000")
.Range("D" & X & ":D" & X).Value = Format(.Range("D" & X & ":D"
& X).Value, "00000")
.Range("E" & X & ":E" & X).Value = Format(.Range("E" & X & ":E"
& X).Value, "00000")
.Range("F" & X & ":F" & X).Value = Format(.Range("F" & X & ":F"
& X).Value, "00000")
Next
End With

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 400
Default Format for Leading Zeros

Before the 'End With' statement, try

.Range("A5:F798").NumberFormat = "000000.00"

You'd need to adjust "000000.00" for your data ...

"DavidW" wrote:


I'm importing a report from another workbook. How can I format column A
of the destination with leading zeros in the code below? The source is
formatted as General. Thanks.


Code:
--------------------
Dim wb As Workbook
Application.ScreenUpdating = False
Set wb = Workbooks.Open("C:\FOReport.xls", True, True)
With ThisWorkbook.Worksheets("Report")
.Range("A5:F798") = ""
.Range("A5:F798").Value = wb.Worksheets("Report").Range("C7:H80").Value
End With
--------------------


--
DavidW
------------------------------------------------------------------------
DavidW's Profile: http://www.excelforum.com/member.php...o&userid=32630
View this thread: http://www.excelforum.com/showthread...hreadid=534117


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Format for Leading Zeros

Hi David,

add this to your code:

Dim wb As Workbook
Application.ScreenUpdating = False
Set wb = Workbooks.Open("C:\FOReport.xls", True, True)
With ThisWorkbook.Worksheets("Report")
.Range("A5:F798") = ""
.Range("A5:F798").Value =
wb.Worksheets("Report").Range("C7:H80").Value

.Range("A5:F798").numberformat="000,000"
'added row of code

End With

Change "000,000" to whatever format code you want.

Regards,

Ivan

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Format for Leading Zeros

Dim wb As Workbook
Application.ScreenUpdating = False
Set wb = Workbooks.Open("C:\FOReport.xls", True, True)
With ThisWorkbook.Worksheets("Report")
.Range("A5:F798") = ""
.Range("A5:F798").Value = wb.Worksheets("Report").Range("C7:H80").Value
.Range("A5:F798").Numberformat = "000000"
End With

this will show 6 or more digits. If the value in the cell is less than 6
digits, it will display leading zeros. Adjust to fit your requirements.

--
Regards,
Tom Ogilvy


"DavidW" wrote:


I'm importing a report from another workbook. How can I format column A
of the destination with leading zeros in the code below? The source is
formatted as General. Thanks.


Code:
--------------------
Dim wb As Workbook
Application.ScreenUpdating = False
Set wb = Workbooks.Open("C:\FOReport.xls", True, True)
With ThisWorkbook.Worksheets("Report")
.Range("A5:F798") = ""
.Range("A5:F798").Value = wb.Worksheets("Report").Range("C7:H80").Value
End With
--------------------


--
DavidW
------------------------------------------------------------------------
DavidW's Profile: http://www.excelforum.com/member.php...o&userid=32630
View this thread: http://www.excelforum.com/showthread...hreadid=534117




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Format for Leading Zeros


Thanks, everyone.

I actually only needed to do the A column. I probably did not make that
clear. The suggestions were still helpful.

This works for just one column:

..Range("A5:A798").numberformat="000000"


--
DavidW
------------------------------------------------------------------------
DavidW's Profile: http://www.excelforum.com/member.php...o&userid=32630
View this thread: http://www.excelforum.com/showthread...hreadid=534117

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
leading zeros in text format BigBrook Excel Discussion (Misc queries) 5 December 11th 08 08:00 PM
leading zeros fall off in csv format. susanmarie Excel Discussion (Misc queries) 4 January 9th 08 07:15 PM
How do I keep leading zeros and format my cells as text? BlabberLots Excel Discussion (Misc queries) 1 February 9th 07 06:29 PM
Format a cell to keep leading zeros. Shadyhosta New Users to Excel 5 July 27th 05 04:37 PM
save text field w/ leading zeros in .csv format & not lose zeros? Ques Excel Discussion (Misc queries) 1 May 4th 05 06:21 PM


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