Philsomedeth
New Member
- Joined
- Jun 5, 2024
- Messages
- 1
- Office Version
- 365
- 2021
- 2019
- Platform
- Windows
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
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
Gambar sebelum Unpivot
Result like this, but ignore/delete blank rows
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
VBA Code:
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
Gambar sebelum Unpivot
Result like this, but ignore/delete blank rows