Copy Data From Multiple Columns in One Sheet to Another & Add Pre-Defined Value

censo

Board Regular
Joined
Dec 25, 2015
Messages
161
Office Version
  1. 2013
Platform
  1. Windows
Hello everyone,

On Sheet1 there's multiple columns with data of which I only need the data of 2 columns; G & H.

The Challenge:

1. The lines of data (rows) will vary (so cannot hard code it to the last line of data that's present at any given moment

2. The data to be copied over from Sheet 1 (columns G & H) cannot include the header information, so copying of cells begins at row 2

3. Column H, Sheet 1 needs to go to Column A, Sheet 2 (under the header - so beginning on row 2)
3a. Column G, Sheet 1 needs to go to Column B, Sheet 2 (under the header - so beginning on row 2)

4. Lastly, the exact string "USD" must be copied down, but only to the last row of data.

Can such a solution be crafted with functions or do we need to employ VBA code?

Thanks!


Excel 2012
ABCDEFGHIJKLMNOPQR
1local_idvendor_urlvendor_variantvendor_stockvendor_pricevendor_shippingtotalreferencecompare_urlcompare_variantcompare_stockcompare_pricecompare_shippingprofit_formulaselling_formulareprice_storereprice_skureprice_pause
2555340http://www.walmart.com/ip/Nine-Stars-18.5-Gallon-Motion-Sensor-Recycle-Unit-and-Trash-Can-Stainless-Steel/15819203186086WAL-15819203#1453535282996000AMAZON_USB0031M9H300
3582037http://www.walmart.com/ip/Hamilton-Beach-33249-4-qt.-Stay-or-Go-Slow-Cooker/21898512124.974.9729.94WAL-21898512#1453535198179200AMAZON_USB005GZ2NDQ0
4582039http://www.homedepot.com/p/Stanley-3-in-1-Rolling-Workshop-STST18613/203367137136.975.9942.96HDP-STST18613#1453535199908900AMAZON_USB009CP4FAK0
5582041http://www.homedepot.com/p/BLACK-DECKER-20-Volt-Max-Lithium-Drill-and-Project-Kit-LDX120PK/204067339169.99069.99HDP-204067339-1#1453535939112000AMAZON_USB00C625KVE0
6582042http://www.walmart.com/ip/46529370112.994.9717.96WAL-46529370#1453535225132700AMAZON_USB00HJ6O4A00
7582043http://www.walmart.com/ip/Dorcy-41-4751-Dorcy-41-4751-180-Lumen-LED-Cyber-Light-Flashlight-Green/27434943114.994.9719.96WAL-27434943#1453535214556900AMAZON_USB008IHDTWS0
8582044http://www.walmart.com/ip/293846830011.8911.89WAL-29384683#145353521673700AMAZON_USB00DXRHQK40
9582046http://www.walmart.com/ip/15409071129.994.9734.96WAL-15409071#1453535202357400AMAZON_USB00336TY0K0
Sheet1



Excel 2012
ABC
1SKUCOSTCURRENCY
2WAL-1581920386USD
3WAL-2189851229.94USD
4HDP-STST1861342.96USD
5HDP-204067339-169.99USD
6WAL-4652937017.96USD
7WAL-2743494319.96USD
8WAL-2938468311.89USD
9WAL-1540907134.96USD
10^^ (From Sheet 1) ^^^^ Auto-populated ^^
11
Sheet2
 
Code:
Worksheets("Sheet2").Activate
e

Thanks for that update.

I ran into a couple of snafus. When I entered the additional code you supplied, I received a dialog box that says:

Run-time error '9':
Subscript out of range

Did I enter this last line the wrong way? The entire code looks like this:

Code:
Sub censo()
    With Worksheets("Sheet1").Range("A1").CurrentRegion
        .Offset(1).Columns("G").Copy Worksheets("AE UPLOAD").Range("A2")
        .Offset(1).Columns("H").Copy Worksheets("AE UPLOAD").Range("B2")
    End With


    With Worksheets("AE UPLOAD").Range("B2").CurrentRegion.Columns("B")
        .Offset(1, 1).Resize(.Rows.Count - 1, 1).Value = "USD"
    End With
    Worksheets("Sheet2").Activate
End Sub

Also, the finished result on Sheet2 is a template I use to upload to a website. For some reason that website doesn't like the file I save (File, Save As, and only saving that one particular sheet as a .csv). It's no big deal, I can simply copy and paste the results into another template and it works just fine.

To save a few extra steps though, what would the code look like to have the results generated on Sheet2 be all highlighted and in copy mode (with the marching ants)?

In other words, the VBA equivalent of pressing CTRL+A to highlight all cells that have data within the worksheet and then CTRL+C to copy.

Thank you!
 
Last edited:
Upvote 0

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
I would say the error is because you don't have a worksheet named "Sheet2"or there's a space after the 2 or before it.

All the other stuff you asked about is a new thread, we're beyond the scope of your original request.
 
Last edited:
Upvote 0
I would say the error is because you don't have a worksheet named "Sheet2"or there's a space after the 2 or before it.

If it were a snake, it would have jumped up and bit me - the answer was right underneath my nose. Haha, yes indeed I've renamed Sheet2 to 'AE UPLOAD'. Thanks for all your assistance.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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