Hi guys,
I have the following situation.
Table 1 in Sheet ("PH")
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Person A
[/TD]
[TD]Country A
[/TD]
[TD]Country B
[/TD]
[TD]Country C
[/TD]
[TD]Country D
[/TD]
[TD]Country E
[/TD]
[/TR]
[TR]
[TD]Product A
[/TD]
[TD="align: center"]5
[/TD]
[TD="align: center"]10
[/TD]
[TD="align: center"]20
[/TD]
[TD="align: center"]30
[/TD]
[TD="align: center"]0
[/TD]
[/TR]
[TR]
[TD]Product B
[/TD]
[TD="align: center"]5
[/TD]
[TD="align: center"]10
[/TD]
[TD="align: center"]25
[/TD]
[TD="align: center"]30
[/TD]
[TD="align: center"]0
[/TD]
[/TR]
[TR]
[TD]Product C
[/TD]
[TD="align: center"]5
[/TD]
[TD="align: center"]10
[/TD]
[TD="align: center"]20
[/TD]
[TD="align: center"]30
[/TD]
[TD="align: center"]0
[/TD]
[/TR]
[TR]
[TD]Product D
[/TD]
[TD="align: center"]5
[/TD]
[TD="align: center"]17
[/TD]
[TD="align: center"]25
[/TD]
[TD="align: center"]30
[/TD]
[TD="align: center"]0
[/TD]
[/TR]
[TR]
[TD]Product E
[/TD]
[TD="align: center"]5
[/TD]
[TD="align: center"]10
[/TD]
[TD="align: center"]20
[/TD]
[TD="align: center"]30
[/TD]
[TD="align: center"]0
[/TD]
[/TR]
</tbody>[/TABLE]
Table 2 in Sheet ("Compiled")
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Person
[/TD]
[TD]Country
[/TD]
[TD]Product
[/TD]
[TD]Description (some formula)
[/TD]
[TD]Value
[/TD]
[/TR]
[TR]
[TD]Person A
[/TD]
[TD="align: center"]Country A
[/TD]
[TD="align: center"]Product A
[/TD]
[TD="align: center"][/TD]
[TD="align: center"]5
[/TD]
[/TR]
[TR]
[TD]Person A
[/TD]
[TD="align: center"]Country A
[/TD]
[TD="align: center"]Product B
[/TD]
[TD="align: center"]<strike></strike>
[/TD]
[TD="align: center"]5
[/TD]
[/TR]
[TR]
[TD]Person A
[/TD]
[TD="align: center"]Country A
[/TD]
[TD="align: center"]Product C
[/TD]
[TD="align: center"]<strike></strike>
[/TD]
[TD="align: center"]5
[/TD]
[/TR]
[TR]
[TD]Person A
[/TD]
[TD="align: center"]Country A
[/TD]
[TD="align: center"]Product D
[/TD]
[TD="align: center"]<strike></strike>
[/TD]
[TD="align: center"]5
[/TD]
[/TR]
[TR]
[TD]Person A
[/TD]
[TD="align: center"]Country A
[/TD]
[TD="align: center"]Product E
[/TD]
[TD="align: center"]<strike></strike>
[/TD]
[TD="align: center"]5
[/TD]
[/TR]
[TR]
[TD]Person A
[/TD]
[TD="align: center"]Country B
[/TD]
[TD="align: center"]Product A<strike></strike>
[/TD]
[TD="align: center"]<strike></strike>
[/TD]
[TD="align: center"]10
[/TD]
[/TR]
</tbody>[/TABLE]
So I want to copy my data from Table 1 to Table 2 as shown above. However, before doing this process, I also wanna clear the existing data in the table 2 (Delete table rows). So far this is the code that I have
So I was just testing out one column value first and I've already encountered an issue. After clearing the data in the table, the code begins to copy data from Table 1 to outside (below the last row) of Table 2.
I also have no idea how I can loop the code to work it the way I want it to be.
Any help would be great. Thank you!!
I have the following situation.
Table 1 in Sheet ("PH")
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Person A
[/TD]
[TD]Country A
[/TD]
[TD]Country B
[/TD]
[TD]Country C
[/TD]
[TD]Country D
[/TD]
[TD]Country E
[/TD]
[/TR]
[TR]
[TD]Product A
[/TD]
[TD="align: center"]5
[/TD]
[TD="align: center"]10
[/TD]
[TD="align: center"]20
[/TD]
[TD="align: center"]30
[/TD]
[TD="align: center"]0
[/TD]
[/TR]
[TR]
[TD]Product B
[/TD]
[TD="align: center"]5
[/TD]
[TD="align: center"]10
[/TD]
[TD="align: center"]25
[/TD]
[TD="align: center"]30
[/TD]
[TD="align: center"]0
[/TD]
[/TR]
[TR]
[TD]Product C
[/TD]
[TD="align: center"]5
[/TD]
[TD="align: center"]10
[/TD]
[TD="align: center"]20
[/TD]
[TD="align: center"]30
[/TD]
[TD="align: center"]0
[/TD]
[/TR]
[TR]
[TD]Product D
[/TD]
[TD="align: center"]5
[/TD]
[TD="align: center"]17
[/TD]
[TD="align: center"]25
[/TD]
[TD="align: center"]30
[/TD]
[TD="align: center"]0
[/TD]
[/TR]
[TR]
[TD]Product E
[/TD]
[TD="align: center"]5
[/TD]
[TD="align: center"]10
[/TD]
[TD="align: center"]20
[/TD]
[TD="align: center"]30
[/TD]
[TD="align: center"]0
[/TD]
[/TR]
</tbody>[/TABLE]
Table 2 in Sheet ("Compiled")
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Person
[/TD]
[TD]Country
[/TD]
[TD]Product
[/TD]
[TD]Description (some formula)
[/TD]
[TD]Value
[/TD]
[/TR]
[TR]
[TD]Person A
[/TD]
[TD="align: center"]Country A
[/TD]
[TD="align: center"]Product A
[/TD]
[TD="align: center"][/TD]
[TD="align: center"]5
[/TD]
[/TR]
[TR]
[TD]Person A
[/TD]
[TD="align: center"]Country A
[/TD]
[TD="align: center"]Product B
[/TD]
[TD="align: center"]<strike></strike>
[/TD]
[TD="align: center"]5
[/TD]
[/TR]
[TR]
[TD]Person A
[/TD]
[TD="align: center"]Country A
[/TD]
[TD="align: center"]Product C
[/TD]
[TD="align: center"]<strike></strike>
[/TD]
[TD="align: center"]5
[/TD]
[/TR]
[TR]
[TD]Person A
[/TD]
[TD="align: center"]Country A
[/TD]
[TD="align: center"]Product D
[/TD]
[TD="align: center"]<strike></strike>
[/TD]
[TD="align: center"]5
[/TD]
[/TR]
[TR]
[TD]Person A
[/TD]
[TD="align: center"]Country A
[/TD]
[TD="align: center"]Product E
[/TD]
[TD="align: center"]<strike></strike>
[/TD]
[TD="align: center"]5
[/TD]
[/TR]
[TR]
[TD]Person A
[/TD]
[TD="align: center"]Country B
[/TD]
[TD="align: center"]Product A<strike></strike>
[/TD]
[TD="align: center"]<strike></strike>
[/TD]
[TD="align: center"]10
[/TD]
[/TR]
</tbody>[/TABLE]
So I want to copy my data from Table 1 to Table 2 as shown above. However, before doing this process, I also wanna clear the existing data in the table 2 (Delete table rows). So far this is the code that I have
Code:
Dim wsComp As Worksheet
Set wsComp = Sheets("Compiled")
Set wsPH = Sheets("PH")
Dim lrow As Long
On Error Resume Next
lrow = wsComp.Range("A" & Rows.Count).End(xlUp).Row
If lrow > 1 Then
wsComp.Range("A2:C" & lrow).ClearContents
wsComp.Range("E" & lrow).ClearContents
[COLOR=#ff0000](Clear contents is not what I'm looking for. But I couldn't think of a substitute code that would only delete the table rows and not the entire row)[/COLOR]
End If
Dim i, j As Long
For i = 2 To wsPH.Cells(Rows.Count, 1).End(xlUp).Row
j = wsComp.Cells(Rows.Count, 1).End(xlUp).Row + 1
wsComp.Cells(j, "A").Value = wsPH.Range("A1").Value
Next
So I was just testing out one column value first and I've already encountered an issue. After clearing the data in the table, the code begins to copy data from Table 1 to outside (below the last row) of Table 2.
I also have no idea how I can loop the code to work it the way I want it to be.
Any help would be great. Thank you!!