Sub CONVERTROWSTOCOL_Oeldere_revisted()
Dim rsht1 As Long, rsht2 As Long, i As Long, Col As Long, wsTest As Worksheet
general setting to the code.
'check if sheet "ouput" already exist
Const strSheetName As String = "Output"
Set wsTest = Nothing
On Error Resume Next
Set wsTest = ActiveWorkbook.Worksheets(strSheetName)
On Error GoTo 0
If wsTest Is Nothing Then
Worksheets.Add.Name = strSheetName
End If
code for making (and checking if the sheet Output exist) a new worksheet output
With Sheets("Output")
.UsedRange.ClearContents 'delete all data on the sheet output
.Range("A1:B1").Value = Array("Name", "Project") 'make a header with the names Name Project
End With
rsht1 = Sheets("sheet1").Range("A" & Rows.Count).End(xlUp).Row 'start counting the rows in sheet 1 from the last row in column A to 1
rsht2 = Sheets("Output").Range("A" & Rows.Count).End(xlUp).Row 'start counting the rows in sheet output from the last row in column A to 1
Col = 9 'begin with the values in column 9
For i = 4 To rsht1 'from last row in sheet 1, column A till row 4
Do While Sheets("sheet1").Cells(1, Col).Value <> "" 'use all columns in row 1 in which the cell contents is <> "" (are not blanc)
rsht2 = rsht2 + 1 'add 1 row in sheet output
Sheets("Output").Range("B" & rsht2).Value = Sheets("sheet1").Range("A" & i).Value 'copy to sheet output, column B to the last row
'(from) take the values in column A
Sheets("Output").Range("A" & rsht2).Value = Sheets("sheet1").Cells(i, Col).Value 'copy to sheet output, column A to the last row
'(from) take the values in all cells (rows) from the give column (in this case 9)
Col = Col + 1 'go to the next column
Loop
Col = 9
Next
With Sheets("Output") 'only in the sheet Output
.Range("A2:A" & .Rows.Count).SpecialCells(4).EntireRow.Delete 'delete the empty values in column A
Columns("A:Z").EntireColumn.AutoFit 'format the cells with for all columns in the range A till Z
End With
End Sub
Hope I explained well enough.
Please reply.
Bookmarks