how to copy and paste a DATA from one sheet to another

charith

Board Regular
Joined
Jan 3, 2014
Messages
152
hello...

i want to copy column A,D,E,F from sheet 1 to sheet 2 column B,C,D,F...

I have a sheet titled "Main" that contains the raw data like the example below. I have another sheets titled "Orders" and . I'm needing a code to copy the data only from column A,D,E,F in "Main" sheet, and paste it in the "Sheet 2" column B,C,D,F based on "sell & buy" values

Sheet(main)
ABCDEF
ORDER TYPE#ORDERSPRICE%
BUY145.780.1
SELL232354.670.15
----
BUY34567890.23

<tbody>
</tbody>

Sheet(Orders)
ABCDFG
A1BUY145.780.1
B2SELL232354.670.15
C1BUY34567890.23
D1

<tbody>
</tbody>

Any help is MUCH appreciated THANK YOU!!
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Here is a clean example workbook to show how the code works.

https://www.dropbox.com/s/xiqgbeuxyez4qoa/LIVE STOCK QUOTES Orders Example Drop Box.xlsm


Click the button and check Orders sheet, click again, check Orders sheet and see that nothing has be copied twice.

Now add in a couple more BUY or SELL in column CE. Click button and those new BUY SELL are copied.

See the small list of #N/A and #DIV/0! formula error signs.

Copy one or two of these into column CE. Click the button and you get a code error.

So those formula error signs returns are causing the problem.

I am not sure how to write code to ignore them. Maybe one of the many viewers of this thread can add something to the code to ignore the formula error signs.

And you could write the formulas to return "" (nothing) or a 0 (zero) instead of the error signs.

Howard
 
Upvote 0
Here is a code to try. I think this will do the trick.

Notice Teeroy name in the sub title. He offered it up and I have tested it and it works fine on the workbook you sent me.

Delete all the other BuyCells codes we have been trying and use this one.

Let me know how it goes.

Howard


Code:
Sub BuyCellsTeeroyNAerror()
Dim c
Dim cO As Range
Dim ceBySel As Range
Dim ceBySelO As Range
Dim lr As Long
Dim lrO As Long

lrO = Sheets("Orders").Cells(Rows.count, 1).End(xlUp).Row
Set ceBySelO = Sheets("Orders").Range("A2:A" & lrO)

Application.ScreenUpdating = False

With Sheets("Main")
    lr = .Range("CE" & Rows.count).End(xlUp).Row
    Set ceBySel = .Range("CE6:CE" & lr)
End With
With Sheets("Orders")
    For Each c In ceBySel
        If Not IsError(c) Then 'new error wrapper
            If WorksheetFunction.CountIf(ceBySelO, c.Offset(, -81)) < 1 _
              And (c.Value = "BUY" Or c.Value = "SELL") Then
                  .Range("B" & Rows.count).End(xlUp)(2).Resize(1, 3).Value = c.Resize(1, 3).Value
                  .Range("E" & Rows.count).End(xlUp)(2).Value = c.Offset(, -35).Value
                  .Range("A" & Rows.count).End(xlUp)(2).Value = c.Offset(, -81).Value
                  Set ceBySelO = ceBySelO.Resize(ceBySelO.Rows.count + 1, 1)
            End If
        End If
    Next
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0
With that code you can delete the formulas in column CD. The code uses column B and range ceBySelO to make sure there is no double copy.

Glad its working for you.

Howard
 
Upvote 0
You would do better to start a new thread with a title something like:

Loop through list of files in Col A and run a macro that is in each file.

Include the link as you have in your post here.

Howard
 
Upvote 0

Forum statistics

Threads
1,216,767
Messages
6,132,599
Members
449,738
Latest member
brianm3y3r

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