transpose skip zeros(0's)

A

ali

Hi

I am trying to transpose a row into column. I want the column to take
only non-zero and non-blank values,e.g.,

1 blank 2 0 blank 3 4

after transpose

1
2
3
4

I am using the following code:

Sub transpose_data()
Dim lastcol As Long
Dim ws As Worksheet
Set ws = Worksheets("sheet2")


lastcol = ws.Cells(1, Columns.Count).End(xlToLeft).Column
With ws
..Range(.Cells(1, 1), .Cells(1,
lastcol)).SpecialCells(xlCellTypeConstants).Copy


..Range("A2").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=True
End With
Application.CutCopyMode = False


End Sub


can somebody guide me how can i add the functionality of transposing
non-zero values only.

Thanks

ali
 
R

Rick Rothstein \(MVP - VB\)

It looks like your code works except that it keeps the 0 cell. Try adding
this line immediately after the With statement and see if it works for
you....

..Range(.Cells(1, 1), .Cells(1, lastcol)).Replace 0, ""

Rick
 
D

Dave Peterson

Check your other post, too.
Hi

I am trying to transpose a row into column. I want the column to take
only non-zero and non-blank values,e.g.,

1 blank 2 0 blank 3 4

after transpose

1
2
3
4

I am using the following code:

Sub transpose_data()
Dim lastcol As Long
Dim ws As Worksheet
Set ws = Worksheets("sheet2")

lastcol = ws.Cells(1, Columns.Count).End(xlToLeft).Column
With ws
.Range(.Cells(1, 1), .Cells(1,
lastcol)).SpecialCells(xlCellTypeConstants).Copy

.Range("A2").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=True
End With
Application.CutCopyMode = False

End Sub

can somebody guide me how can i add the functionality of transposing
non-zero values only.

Thanks

ali
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top