VBA: Auto-fill cells based on user defined values and quantity

Dracius

New Member
Joined
Mar 23, 2018
Messages
9
Hello,

First time poster, long time reader.

I'm trying to figure out a way using VBA where a user can specify values in 2 adjacent cells with a quantity in a 3rd cell, hit a button and have it insert the values entered a number of times equal to the quantity specified.

Example Input:
ProductPriceQTY
Dog Socks$2.954
Cat Mittens$1.994

<tbody>
</tbody>





Example Output:
ProductPrice
Dog Socks$2.95
Dog Socks$2.95
Dog Socks$2.95
Dog Socks$2.95
Cat Mittens$1.99
Cat Mittens$1.99
Cat Mittens$1.99
Cat Mittens$1.99

<tbody>
</tbody>















The actual product list has 50+ products and the prices can vary so using formulas isn't ideal. There can also be up to 30 different types of product per order. I figure the best approach is using VBA and having the output values specified by the user, then executing it based on the # entered into the quantity, and outputting the values into the "next empty cell" on the output sheet.

I made a sample workbook, but I don't see a way to attach it.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Received the answers another board, this thread can be closed.

<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;">Private Sub Submit_Click()
Application.ScreenUpdating = False
Dim LastRow As Long
LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Dim x As Long
For x = 2 To LastRow
Cells(x, 1).Resize(, 2).Copy
Sheets("Output").Cells(Sheets("Output").Rows.Count, "C").End(xlUp).Offset(1, 0).Resize(Cells(x, 3)).PasteSpecial xlPasteValues
Next x
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub</code>
 
Upvote 0
In future, when posting questions here that you have asked elsewhere, please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0
Sorry, I'll remember that for the future.

I would edit my post with the cross-reference, but I lack permissions to edit my posts or add attachments, which is why I posted on the other forum too (it allows attachments).
 
Upvote 0

Forum statistics

Threads
1,214,561
Messages
6,120,228
Members
448,951
Latest member
jennlynn

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