Hi. Good day to you.
I would like to populate a "template" worksheet based on an Excel Table like this:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]ClientID[/TD]
[TD]Bank
[/TD]
[TD]Account[/TD]
[TD]Problem[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Big bank[/TD]
[TD]987987987[/TD]
[TD]Didn't pay[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]North bank[/TD]
[TD]654654654[/TD]
[TD]Delayed pay[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]South bank[/TD]
[TD]654654654[/TD]
[TD]Low credit[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Easy bank[/TD]
[TD]852852852[/TD]
[TD]Bankrupt[/TD]
[/TR]
</tbody>[/TABLE]
However, I can only copy 3 of the 4 rows above into the "template" worksheet, so I will need another one to be created. Each 3 records, actually, so if a Client has 7 records, I would need 3 "template" worksheets to be created.
Can you give me a brief example of how to do this?
In the example above, I tried to loop from the first record, and copy the two rows below from that position, and skip those rows starting with the fourth to continue again. It only copies the first record.
Please, give me a little push in how to do such thing, any suggestion is welcome.
I would like to populate a "template" worksheet based on an Excel Table like this:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]ClientID[/TD]
[TD]Bank
[/TD]
[TD]Account[/TD]
[TD]Problem[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Big bank[/TD]
[TD]987987987[/TD]
[TD]Didn't pay[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]North bank[/TD]
[TD]654654654[/TD]
[TD]Delayed pay[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]South bank[/TD]
[TD]654654654[/TD]
[TD]Low credit[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Easy bank[/TD]
[TD]852852852[/TD]
[TD]Bankrupt[/TD]
[/TR]
</tbody>[/TABLE]
However, I can only copy 3 of the 4 rows above into the "template" worksheet, so I will need another one to be created. Each 3 records, actually, so if a Client has 7 records, I would need 3 "template" worksheets to be created.
Can you give me a brief example of how to do this?
Code:
<code>Private Sub btnCreateForms_Click()
Dim cell As Range, rng As Range
Set rng = Sheets("Temp").Range("tbProblems[Bank]")
For Each cell In rng
Sheets("Template").Range("D24").Value = cell.Value
Sheets("Template").Range("L24").Value = cell.Offset(0, 1).Value
Sheets("Template").Range("D29").Value = cell.Offset(0, 3).Value
Sheets("Template").Range("D32").Value = cell.Offset(1, 0).Value
Sheets("Template").Range("L32").Value = cell.Offset(1, 1).Value
Sheets("Template").Range("D37").Value = cell.Offset(1, 3).Value
Sheets("Template").Range("D40").Value = cell.Offset(2, 0).Value
Sheets("Template").Range("L40").Value = cell.Offset(2, 1).Value
Sheets("Template").Range("D45").Value = cell.Offset(2, 3).Value
GoTo Nextiteration
GoTo Nextiteration
Nextiteration:
Next cell
End Sub</code>
In the example above, I tried to loop from the first record, and copy the two rows below from that position, and skip those rows starting with the fourth to continue again. It only copies the first record.
Please, give me a little push in how to do such thing, any suggestion is welcome.