VBA Copy certain cells and columns to another sheet

karl10220

New Member
Joined
Feb 28, 2024
Messages
25
Office Version
  1. 365
Platform
  1. Windows
I am stumped with what to do with this situation. I am trying to take data from a row with multiple variables and place it in a column. For each bottle purchased, there is a new price point based on a different order volume. That is currently in a row and I'd like it to be transferred to a column, but I'd need various data points from the row to then be pasted on each row for the individual data point. You'll see in the image. But Item 123 from Store 456, has quantities that relate to specific pricing, so I need the new sheet in column/table format to show 123-456-qty1-price1; in row 2 123-456-qty2-price2; etc. 7 times for each 123-456 combination. There are 2000 rows, so doing this manually is not an option, but 2000 rows will spit out 14000 lines it appears in this new format. Thank you so much for your help!

Note: the yellow column headers represent a new sheet "Sheet 2" with the same columns referenced .
 

Attachments

  • Capture.JPG
    Capture.JPG
    134.8 KB · Views: 6
to pull M, O, Q, S, U, W, Y for the qty. change the following

from
.Cells(lr + q, "L") = Cells(r, 12 + q) ' quantity- starts at column m
to
.Cells(lr + q, "L") = Cells(r, 11 + q*2) ' quantity- starts at column m

the price is already set to AB, AD, AF, AH, AJ, AL, AN in the original code
 
Upvote 0

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Lastly, can columns AB-AN be rounded to 4 decimal points maximum? Currently it spits out 8 or so.
You can either adjust the cell formatting from those columns to only show 4 decimals.
Or you can use the ROUND function to round those entries to 4 decimals (the ROUND function exists both as a Worksheet function and a VBA function).
 
Upvote 0
Thank you both! I can't get the rounding feature to work, but this is a minimal problem!
 
Upvote 0
Another perfectionist question here, can we 'clear all contents' after Row 1 on Sheet 2?

As for the rounding, since these will get uploaded into another program can you help write the VBA for rounding price to 4 spots?
 
Upvote 0
change
' .Cells.ClearContents 'remove all data from sheet 2
to
.Range("F2:M" & .[F1].End(xlDown).Row).ClearContents

and

.Cells(lr + q, "M") = Cells(r, 26 + q * 2)
to
.Cells(lr + q, "M") = Round(Cells(r, 26 + q * 2), 4) 'this will round to 4 places
 
Upvote 0
Thank you so much! I have now applied the macro to the larger data set (which I anticipate to spit out over 14,000 rows!) and it stopped after row 2886 (half way) and gave an error Run-time error '13': Type Mismatch in the command

.Cells(lr + q, "M") = Round(Cells(r, 26 + q * 2), 4) 'this will round to 4 places 'price - starte at column AB


Any ideas?

EDIT:
Fixed the error on my sheet. It found a 'N/A' cell. I'm sorry to alarm. This has been such a learning for me and I am so grateful!
 
Upvote 0

Forum statistics

Threads
1,215,094
Messages
6,123,071
Members
449,092
Latest member
ipruravindra

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