VBA Beginner Question

Final Frontier

New Member
Joined
Sep 16, 2014
Messages
17
I’ve worked with simple macros but am wondering if something more complex is possible (this actually might be simple as well).

I have a set of data with item numbers, quantity, price, and account numbers. The letters in the first row are the columns. Example below:

Tab 1
[TABLE="width: 480"]
<tbody>[TR]
[TD]A
[/TD]
[TD]B
[/TD]
[TD]C
[/TD]
[TD]D
[/TD]
[TD]E
[/TD]
[/TR]
[TR]
[TD]Account 1
[/TD]
[TD]Item number
[/TD]
[TD]Account 2
[/TD]
[TD]Quantity
[/TD]
[TD]Price
[/TD]
[/TR]
[TR]
[TD]202
[/TD]
[TD]11
[/TD]
[TD]102
[/TD]
[TD]6
[/TD]
[TD]100
[/TD]
[/TR]
[TR]
[TD]203
[/TD]
[TD]22
[/TD]
[TD]103
[/TD]
[TD]7
[/TD]
[TD]200
[/TD]
[/TR]
[TR]
[TD]204
[/TD]
[TD]33
[/TD]
[TD]104
[/TD]
[TD]10
[/TD]
[TD]300
[/TD]
[/TR]
[TR]
[TD]205
[/TD]
[TD]44
[/TD]
[TD]105
[/TD]
[TD]30
[/TD]
[TD]400
[/TD]
[/TR]
[TR]
[TD]206
[/TD]
[TD]55
[/TD]
[TD]106
[/TD]
[TD]5
[/TD]
[TD]500
[/TD]
[/TR]
</tbody>[/TABLE]

And then on a second tab I have data with a percentage that is supposed to go to each person:

Tab 2
[TABLE="width: 465"]
<tbody>[TR]
[TD]A
[/TD]
[TD]B
[/TD]
[TD]C
[/TD]
[TD]D
[/TD]
[TD]E
[/TD]
[TD]F
[/TD]
[TD]G
[/TD]
[TD]H
[/TD]
[TD]I
[/TD]
[/TR]
[TR]
[TD]location
[/TD]
[TD]State
[/TD]
[TD]Zip
[/TD]
[TD]%
[/TD]
[TD]NAME ID
[/TD]
[TD]Name
[/TD]
[TD]Account 3
[/TD]
[TD]Account 4
[/TD]
[TD]ID
[/TD]
[/TR]
[TR]
[TD]New York
[/TD]
[TD]NY
[/TD]
[TD]
[/TD]
[TD]30%
[/TD]
[TD]A
[/TD]
[TD]Jon
[/TD]
[TD]101
[/TD]
[TD]201
[/TD]
[TD]E
[/TD]
[/TR]
[TR]
[TD]Pittsburgh
[/TD]
[TD]PA
[/TD]
[TD]
[/TD]
[TD]30%
[/TD]
[TD]B
[/TD]
[TD]Mike
[/TD]
[TD]201
[/TD]
[TD]202
[/TD]
[TD]F
[/TD]
[/TR]
[TR]
[TD]Dallas
[/TD]
[TD]TX
[/TD]
[TD]
[/TD]
[TD]40%
[/TD]
[TD]C
[/TD]
[TD]Adam
[/TD]
[TD]301
[/TD]
[TD]203
[/TD]
[TD]J
[/TD]
[/TR]
</tbody>[/TABLE]

There’s a third tab where the final information needs to be. Essentially what needs to happen is each person will get a percentage of each line from tab 1. So for the first line in tab 1, Jon will get 30% of the quantity and price, Mike 30%, and Adam 40%. This will need to be done for each line in tab 1. So for example the final product for the first line should look like this:

[TABLE="width: 467"]
<tbody>[TR]
[TD]A
[/TD]
[TD]B
[/TD]
[TD]C
[/TD]
[TD]D
[/TD]
[TD]E
[/TD]
[TD]F
[/TD]
[TD]G
[/TD]
[TD]H
[/TD]
[/TR]
[TR]
[TD]Blank
[/TD]
[TD]Item
[/TD]
[TD]Quantity
[/TD]
[TD]Sales
[/TD]
[TD]Account 1
[/TD]
[TD]Account 2
[/TD]
[TD]Account 3
[/TD]
[TD]Account 4
[/TD]
[/TR]
[TR]
[TD]
[/TD]
[TD]11
[/TD]
[TD]1.8
[/TD]
[TD]30
[/TD]
[TD]202
[/TD]
[TD]102
[/TD]
[TD]101
[/TD]
[TD]201
[/TD]
[/TR]
[TR]
[TD]
[/TD]
[TD]11
[/TD]
[TD]1.8
[/TD]
[TD]30
[/TD]
[TD]202
[/TD]
[TD]102
[/TD]
[TD]201
[/TD]
[TD]202
[/TD]
[/TR]
[TR]
[TD]
[/TD]
[TD]11
[/TD]
[TD]2.4
[/TD]
[TD]40
[/TD]
[TD]202
[/TD]
[TD]102
[/TD]
[TD]301
[/TD]
[TD]203
[/TD]
[/TR]
</tbody>[/TABLE]

The data I have is much larger so I was hoping someone could direct me of how to write a macro for this. I’m stuck on how to do this and am admittedly still learning the basics of vba. Is there a way you can write a code that can take data from each heading and multiply by a percentage, and then also carry over the item numbers and accounts?

Any help would be appreciated. Even if you can just direct me to different functions or the general process to use. Thanks in advance.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Forum statistics

Threads
1,222,316
Messages
6,165,304
Members
451,950
Latest member
WH2000

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