Sub copyFilledCells()
Dim colsToCopy() As String
colsToCopy = Split("B,E,H,K,N,Q,T,W", ",") 'get columns to copy into an array
Sheet1.Activate 'start on the first sheet, where the data is
Sheet2.Cells.ClearContents 'clear output sheet
For i = 0 To UBound(colsToCopy)
Call copyColumn(colsToCopy(i), Sheet1, Sheet2)
Next i
MsgBox "Done!"
Sheet2.Activate
End Sub
Sub copyColumn(colLetter As String, shIn As Worksheet, shOut As Worksheet)
Dim myCell As Range
If Range(colLetter & Rows.Count).End(xlUp).Row < 7 Then Exit Sub 'no data here
For Each myCell In shIn.Range(colLetter & "7", Range(colLetter & Rows.Count).End(xlUp)) 'row 7 to to the last row with data, with column requested
shOut.Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = myCell.Value 'put value in row to the next available cell in column A of output sheet
Next myCell
End Sub
Sub copyFilledCells()
Dim colsToCopy() As String
colsToCopy = Split("B,E,H,K,N,Q,T,W", ",") 'get columns to copy into an array
Sheet1.Activate 'start on the first sheet, where the data is
Sheet2.Cells.ClearContents 'clear output sheet
For i = 0 To UBound(colsToCopy)
Call copyColumn(colsToCopy(i), Sheet1, Sheet2)
Next i
MsgBox "Done!"
Sheet2.Activate
End Sub
Sub copyColumn(colLetter As String, shIn As Worksheet, shOut As Worksheet)
Dim myCell As Range
If Range(colLetter & Rows.Count).End(xlUp).Row < 7 Then Exit Sub 'no data here
For Each myCell In shIn.Range(colLetter & "7", Range(colLetter & Rows.Count).End(xlUp)) 'row 7 to to the last row with data, with column requested
If shOut.Range("A1").Value = "" Then
shOut.Range("A1").Value = myCell.Value
Else
shOut.Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = myCell.Value 'put value in row to the next available cell in column A of output sheet
End If
Next myCell
End Sub
See attached update,Sub collatecols()
For i = 2 To 24 Step 3
If Sheet1.Cells(7, i) <> "" Then
Sheet1.Range(Sheet1.Cells(7, i), Sheet1.Cells(Sheet1.Cells(Rows.Count, i).End(xlUp).Row, i)).Copy Sheets("sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
End If
Next i
End Sub
Sub collatecols()
For i = 2 To 24 Step 3
Set fr = Sheet1.Cells(7, i)
If fr <> "" Then
Set lr = Sheet1.Cells(Sheet1.Cells(Rows.Count, i).End(xlUp).Row, i)
Set tr = Sheet2.Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
Sheet1.Range(fr, lr).Copy tr
End If
Next i
If Sheet2.Range("A1") = "" Then Sheet2.Range("A1").EntireRow.Delete
End Sub
Please explain what the output in column A looks like for Sheet 2, the first couple rows.
Dave