0

I got this VBA code on the internet and I have adapted it to my data, but I don't know how to ignore/delete blank rows in the code I have tried various ways but didn't get the results I want

Public Sub unpivotData()
   
    Dim staticColumnCount As Integer
    Dim oldRow As Long, theDate As Long, newRow As Long
    Dim inputSheet As Worksheet, outputSheet As Worksheet
    Dim inputSheetName As String, outputSheetName As String

    staticColumnCount = 4
    outputSheetName = "Output"
    inputSheetName = ActiveSheet.Name
    
    
    Set inputSheet = ActiveWorkbook.Worksheets("Sheet3")
    Set outputSheet = Worksheets.Add
            outputSheet.Select
                outputSheet.Name = outputSheetName
    

        For i = 1 To staticColumnCount
            outputSheet.Cells(1, i).Value = inputSheet.Cells(1, i).Value
        Next i

            outputSheet.Cells(1, staticColumnCount + 1).Value = "RTA"
            outputSheet.Cells(1, staticColumnCount + 2).Value = "QTY"
    
            inputRow = 2
            outputRow = 2
    
                Do While inputSheet.Cells(inputRow, 1).Value <> ""
                    inputColumn = staticColumnCount + 1
                        Do While inputSheet.Cells(1, inputColumn).Value <> ""
                            For j = 1 To staticColumnCount
                                outputSheet.Cells(outputRow, j).Value = inputSheet.Cells(inputRow, j)
                            Next j
                        outputSheet.Cells(outputRow, staticColumnCount + 1).Value = inputSheet.Cells(1, inputColumn)
                            outputSheet.Cells(outputRow, staticColumnCount + 2).Value = inputSheet.Cells(inputRow, inputColumn)
                            inputColumn = inputColumn + 1
                        outputRow = outputRow + 1
                        Loop
                    inputRow = inputRow + 1
                Loop
    
    outputSheet.Columns("E:E").NumberFormat = "m/d/yyyy"
        outputSheet.Cells(1, 1).Select
    
    MsgBox "Data has been transposed"


End Sub

Original After

I hope there is someone who is able to change/add some code that ignore/delete blank rows in the code i hope this make sense

Thank u :)

2
  • This is a duplicate question. OP has asked 16 hrs back, it was marked duplicate since OP had not shown anything what they have tried. Even when marking it as duplicate OP deleted their previous question and asked it again. Here is the older question Commented Jun 6, 2024 at 2:03
  • There are about tons of questions on unpivoting please try to do research, when the post was marked duplicate it had really something to do. Commented Jun 6, 2024 at 2:06

0