PDA

View Full Version : Format output



GSWoodward
06-26-2009, 07:58 AM
I am using the following code. I want the output to be in txt format so i will not drop leading zeros.
Any help would be greatly appreciated

Sub Zozo()
' hard-coded: the place we start looking
nCol = 1
nRow = 2
' hard-coded: here's where we're sticking the output
dR = 7
dC = 4
rCi = 5
rC = rCi
prev = -1

While Not IsEmpty(Application.ActiveSheet.Cells(nRow, nCol))
cust = Application.ActiveSheet.Cells(nRow, nCol).Value
If (cust <> prev) Then
dR = dR + 1

prev = cust
rC = rCi
Application.ActiveSheet.Cells(dR, dC).Value = cust
End If

Application.ActiveSheet.Cells(dR, rC).Value = Application.ActiveSheet.Cells(nRow, nCol + 1).Value
rC = rC + 1
nRow = nRow + 1
Wend
End Sub

p45cal
06-26-2009, 09:21 AM
does this do it?Sub Zozo()
' hard-coded: the place we start looking
nCol = 1
nRow = 2
' hard-coded: here's where we're sticking the output
dR = 7
dC = 4
rCi = 5
rC = rCi
prev = -1
With Application.ActiveSheet
While Not IsEmpty(.Cells(nRow, nCol))
cust = .Cells(nRow, nCol).Value
If (cust <> prev) Then
dR = dR + 1
prev = cust
rC = rCi
.Cells(nRow, nCol).Copy
Cells(dR, rC).PasteSpecial Paste:=xlPasteValuesAndNumberFormats
End If
.Cells(nRow, nCol + 1).Copy
.Cells(dR, rC).PasteSpecial Paste:=xlPasteValuesAndNumberFormats
rC = rC + 1
nRow = nRow + 1
Wend
End With
Application.CutCopyMode = False
End Sub

GSWoodward
06-26-2009, 09:51 AM
But now I am not getting colum 1, only colum 2 arrange as rows. But the format is correct

p45cal
06-26-2009, 10:08 AM
my typo, change the earlier instance of:
Cells(dR, rC).PasteSpecial Paste:=xlPasteValuesAndNumberFormats
to
Cells(dR, dC).PasteSpecial Paste:=xlPasteValuesAndNumberFormats

mikerickson
06-26-2009, 10:14 AM
Replace these lines
...
Application.ActiveSheet.Cells(dR, dC).Value = "'" & cust
...
Application.ActiveSheet.Cells(dR, rC).Value = "'" & Application.ActiveSheet.Cells(nRow, nCol + 1).Value
...