How to transpose Excel columns into a new range ignoring blank cells
Question:
Answers:
I'm new at VBA and tried finding already existing solutions but none answered fully my requirements:
My initial list has holes (blanks) and I need to list the results as transposed without these blank fields
column A has files # and then 5 columns with prices but some are having only one price others 2 others 3 etc but never more than 3 prices. And these are varying from one month to another with hundred lines of it.
My first trials were no success as I couldn't find the totals expected. My initial code was the following but it doesn't catch last 2 columns as there are blank fields in between:
Result to reach:

My initial list has holes (blanks) and I need to list the results as transposed without these blank fields

column A has files # and then 5 columns with prices but some are having only one price others 2 others 3 etc but never more than 3 prices. And these are varying from one month to another with hundred lines of it.
My first trials were no success as I couldn't find the totals expected. My initial code was the following but it doesn't catch last 2 columns as there are blank fields in between:
Dim LR As Long, Rw As Long, Col As Long, LastCol As Long, CurRw As Long
Application.ScreenUpdating = False
LR = Range("A" & Rows.Count).End(xlUp).Row
Range("B:B").Insert xlShiftToRight
For Rw = LR To 2 Step -1
If Range("D" & Rw) <> "" Then
LastCol = Cells(Rw, Columns.Count).End(xlToLeft).Column
Rows(Rw + 1).Resize(LastCol - 3).Insert xlShiftDown
Range("A" & Rw).Resize(LastCol - 2) = Range("A" & Rw)
Range("B" & Rw).Resize(LastCol - 2).Value = Range("C" & Rw).Resize(LastCol + 5).Value
Range("C" & Rw).Resize(1, LastCol - 2).Copy
Range("B" & Rw).Resize(LastCol - 2).PasteSpecial xlPasteAll, Transpose:=True
Range("C1").Resize(1, LastCol - 2).Copy
Range("C" & Rw).PasteSpecial xlPasteAll, Transpose:=True
Else
Range("C" & Rw).Copy Range("B" & Rw)
Range("C1").Copy Range("C" & Rw)
End If
Next Rw"
Thanks for your help. wishing this is now easier to understand and assist ;-)Result to reach:

Answers:
using your image with file in A1, would be along these lines

Sub Example()
Range("b2").Resize(1, 10).SpecialCells(xlCellTypeConstants, xlNumbers).Copy
Range("m2").Value = Range("b2").Resize(1, 10).SpecialCells(xlCellTypeConstants, xlNumbers).Count
Range("n2").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=True, Transpose:=True
End Sub
count will be in M and Transposed in N
Commentaires
Enregistrer un commentaire