Converting listed data to pivot table format - repeatedly copying and pasting between two specified instances

financial_analyst22

New Member
Joined
May 21, 2019
Messages
1
Hi Everyone,

I am no VBA expert and appreciate any help you can provide. I would like to learn how to search for a before and after instance to copy and paste information in between those two instances. And then repeat the process. This helps to create a format usable for a pivot table.

For example if my report looks like: 1) the account information (and beginning balance) in its own row, 2) all the transactions for that account in the rows below, followed by 3) an ending balance, and then it repeats with a new account followed by those transactions and an ending balance, and so on
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Row #[/TD]
[TD]Column A[/TD]
[TD]Column B[/TD]
[TD]Column C[/TD]
[TD]Column D[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD][/TD]
[TD]Account Information 1[/TD]
[TD][/TD]
[TD]"Beginning Balance"[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD][/TD]
[TD]Date of Transaction[/TD]
[TD]Transaction Info.[/TD]
[TD]Transaction Info.[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD][/TD]
[TD]Date of Transaction[/TD]
[TD]Transaction Info.[/TD]
[TD]Transaction Info.[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD][/TD]
[TD]Ending Balance thru...[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD][/TD]
[TD]Account Information 2[/TD]
[TD][/TD]
[TD]"Beginning Balance"[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD][/TD]
[TD]Date of Transaction[/TD]
[TD]Transaction Info.[/TD]
[TD]Transaction Info.[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD][/TD]
[TD]Ending Balance thru...[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD][/TD]
[TD]Account Information 3[/TD]
[TD][/TD]
[TD]"Beginning Balance"[/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD][/TD]
[TD]Account Information 4[/TD]
[TD][/TD]
[TD]"Beginning Balance"[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD][/TD]
[TD]Date of Transaction[/TD]
[TD]Transaction Info.[/TD]
[TD]Transaction Info.[/TD]
[/TR]
[TR]
[TD]11[/TD]
[TD][/TD]
[TD]Ending Balance thru...[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

I would like to:
1) Search for "Beginning Balance" in column D. There is a beginning balance instance in column D for every new account.
2) Then I would like to copy a TRIMMED version (there are extra spaces that I don't want) of the column B account information into column A next to every Transaction until I reach the ending balance row.
3) I would like this to repeat for every account section.
4) Final step: delete the account information/beginning balance rows & the ending balance rows

Note: There are some instances where there is a row for an account and beginning balance but no transactions and no ending balance row so those will need to be skipped over. (Example in row 8 for Account Information 3)

Goal Table:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Row #[/TD]
[TD]Column A[/TD]
[TD]Column B[/TD]
[TD]Column C[/TD]
[TD]Column D[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Account Information 1[/TD]
[TD]Date of Transaction[/TD]
[TD]Transaction Info.[/TD]
[TD]Transaction Info.[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Account Information 1[/TD]
[TD]Date of Transaction[/TD]
[TD]Transaction Info.[/TD]
[TD]Transaction Info.[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Account Information 2[/TD]
[TD]Date of Transaction[/TD]
[TD]Transaction Info.[/TD]
[TD]Transaction Info.[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]Account Information 4[/TD]
[TD]Date of Transaction[/TD]
[TD]Transaction Info.[/TD]
[TD]Transaction Info.[/TD]
[/TR]
</tbody>[/TABLE]

Thank you in advance for your help!
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,223,888
Messages
6,175,208
Members
452,618
Latest member
Tam84

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top