I have a macro that i have successfully run several times in the past. I have it linked to a button on my quick access toolbar.
I have a dataset on "sheet1" with row 1 being the column headers and column 1 being a unique identifier. The data fields are numbers and the macro simply creates a new row on sheet 2 for any row/column intersection that contains a number. So instead of having 50 columns I have 3, one with the unique identifier, one with the column heading and the last with the quantities.
I create a blank "sheet2" and attempt to run the macro and nothing happens. I've had this problem in the past and gotten it to work but i use it so infrequently I can't figure out the problem.
Any idea what i might be doing wrong? Thanks.
Sub flattenWorkSheet()
Application.ScreenUpdating = False
RowCount = 2
PrintRow = 1
With ActiveWorkbook
Do Until ActiveWorkbook.Sheets(1).Cells(Rows.Count, 1) = ""
ColumnCount = 2
Do Until ActiveWorkbook.Sheets(1).Cells(1, ColumnCount) = ""
If Sheets(1).Cells(RowCount, ColumnCount) <> "" Then
Sheets(2).Cells(PrintRow, 1) = Sheets(1).Cells(RowCount, 1)
Sheets(2).Cells(PrintRow, 2) = Sheets(1).Cells(1, ColumnCount)
Sheets(2).Cells(PrintRow, 3) = Sheets(1).Cells(RowCount, ColumnCount)
PrintRow = PrintRow + 1
End If
ColumnCount = ColumnCount + 1
Loop
RowCount = RowCount + 1
Loop
End With
Application.ScreenUpdating = True
End Sub
I have a dataset on "sheet1" with row 1 being the column headers and column 1 being a unique identifier. The data fields are numbers and the macro simply creates a new row on sheet 2 for any row/column intersection that contains a number. So instead of having 50 columns I have 3, one with the unique identifier, one with the column heading and the last with the quantities.
I create a blank "sheet2" and attempt to run the macro and nothing happens. I've had this problem in the past and gotten it to work but i use it so infrequently I can't figure out the problem.
Any idea what i might be doing wrong? Thanks.
Sub flattenWorkSheet()
Application.ScreenUpdating = False
RowCount = 2
PrintRow = 1
With ActiveWorkbook
Do Until ActiveWorkbook.Sheets(1).Cells(Rows.Count, 1) = ""
ColumnCount = 2
Do Until ActiveWorkbook.Sheets(1).Cells(1, ColumnCount) = ""
If Sheets(1).Cells(RowCount, ColumnCount) <> "" Then
Sheets(2).Cells(PrintRow, 1) = Sheets(1).Cells(RowCount, 1)
Sheets(2).Cells(PrintRow, 2) = Sheets(1).Cells(1, ColumnCount)
Sheets(2).Cells(PrintRow, 3) = Sheets(1).Cells(RowCount, ColumnCount)
PrintRow = PrintRow + 1
End If
ColumnCount = ColumnCount + 1
Loop
RowCount = RowCount + 1
Loop
End With
Application.ScreenUpdating = True
End Sub