Hi,
I copy and paste a report statement to my excel each time. It contains many tables within the report. I have a macro to delete every row except for rows that contain a "text" (table in this case) as shown below and paste the header back to the table after initially being deleted as part of rows that doesn't contain the "text" as specified in the code.
I wonder if there is a more efficient way of keeping the header by not deleting it in the first place as opposed to pasting it @ the end - this way, I could probably use it for my other report statement to clean up the blank rows and other data rows that I don't need without deleting the first header.
Sample Table
<tbody>
</tbody>
Macro Code
For i = Selection.Rows.Count To 1 Step -1
If (Cells(i, "G").Value) <> "Table" Then
Selection.Rows(i).EntireRow.Delete
End If
Next i
Range("A1").Select
Selection.Insert Shift:=xlDown
Range("A1").Value = "Client ID"
Range("B1").Value = "Client Name"
Range("C1").Value = "Item"
Range("D1").Value = "Amount"
Range("E1").Value = "Referring Agent"
"
I copy and paste a report statement to my excel each time. It contains many tables within the report. I have a macro to delete every row except for rows that contain a "text" (table in this case) as shown below and paste the header back to the table after initially being deleted as part of rows that doesn't contain the "text" as specified in the code.
I wonder if there is a more efficient way of keeping the header by not deleting it in the first place as opposed to pasting it @ the end - this way, I could probably use it for my other report statement to clean up the blank rows and other data rows that I don't need without deleting the first header.
Sample Table
Report Name | ||||
Reporting Time | ||||
Statement Period | ||||
New York | ||||
Client ID | Client Name | Item | Amount | Refering Agent |
1 | John | Table | 1 | Hammett |
2 | Maria | Desk | 2 | Sam |
North Carolina | ||||
Client ID | Client Name | Item | Amount | Refering Agent |
1 | John | Sofa | 1 | Hammett |
3 | Robert | Sofa | 1 | Jennifer |
South Carolina | ||||
Client ID | Client Name | Item | Amount | Refering Agent |
2 | Maria | Table | 2 | Sam |
4 | Micah | Bed | 1 | Hammett |
<tbody>
</tbody>
Macro Code
For i = Selection.Rows.Count To 1 Step -1
If (Cells(i, "G").Value) <> "Table" Then
Selection.Rows(i).EntireRow.Delete
End If
Next i
Range("A1").Select
Selection.Insert Shift:=xlDown
Range("A1").Value = "Client ID"
Range("B1").Value = "Client Name"
Range("C1").Value = "Item"
Range("D1").Value = "Amount"
Range("E1").Value = "Referring Agent"
"