VBA Needed for Copying "X" # of IDs 3 times in separate rows and summing, separating and placing associated cost numbers and in another colum

mrpayne

New Member
Joined
Dec 13, 2018
Messages
6
Title is too long but here is an example of what I am trying to get:
I am a newbee when it comes to this type of coding so any help is greatly appreciated.

Example Input Worksheet #1 with Original Data
Column A (IDs) Column B Column C Column D Column E
12345 $2 $1 $6 $3
56789 $4 $1 $7 $5
35791 $5 $1 $8 $4

Example Output New Worksheet #2 using New VBA Code to create the numbers or sums. Need Macro as IDs will change monthly and sheet will need to recalc monthly.
Column A (IDs) Column B Notes and Comments
12345 $3 (Sum of Column B and C for this ID above for 1 of 3 same ID)
12345 $6 (Column D value above for 2 of 3 same ID)
12345 $3 (Column E value above for 3 of 3 same ID)
56789 $5 (Sum of Column B and C for this ID above)
56789 $7 (Column D value above)
56789 $5 (Column E value above)
35791 $6 (Sum of Column B and C for this ID above)
35791 $8 Same as above
35791 $4 Same as above
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
try this.

create a new sheet and name it "Results" (without the quotes)
then run this macro. make sure your main sheet is the active sheet.

Code:
Sub do_it()

wr = 1

With Worksheets("Results")
.Cells.ClearContents
For r = 2 To Cells(Rows.Count, "A").End(xlUp).Row
.Cells(wr, "A") = Cells(r, "A")
.Cells(wr, "B") = Cells(r, "B") + Cells(r, "C")
.Cells(wr + 1, "A") = Cells(r, "A")
.Cells(wr + 1, "B") = Cells(r, "D")
.Cells(wr + 2, "A") = Cells(r, "A")
.Cells(wr + 2, "B") = Cells(r, "E")
wr = wr + 3
Next r
End With
End Sub

hth,
Ross
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,755
Members
448,989
Latest member
mariah3

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