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!!
 
Sir , i use this code to copy 83,84,and 85 columns (Order Type, #Order ,Price) in "Main sheet " to 2, 3, 4 columns in "Order sheet"
but it copied only the 83 column only :(

Option Explicit


Sub BuyCells()
Dim c As Range
Dim rngA As Range
Dim lr As Long


lr = Cells(Rows.Count, 1).End(xlUp).Row
Set rngA = Range("CE6:CE" & lr)


Application.ScreenUpdating = False


For Each c In rngA


If c = "BUY" Or c = "SELL" Then
c.Copy
Sheets("Orders1").Range("B" & Rows.Count).End(xlUp)(2).PasteSpecial Paste:=xlPasteValues

c.Offset(, 83).Resize(1, 2).Copy
Sheets("Orders1").Range("G" & Rows.Count).End(xlUp)(2).PasteSpecial Paste:=xlPasteValues


End If


Next
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Try this.


Code:
Option Explicit

 Sub BuyCells()
 Dim c As Range
 Dim ceBySel As Range
 Dim lr As Long

 lr = Cells(Rows.Count, 1).End(xlUp).Row
 Set ceBySel = Range("CE6:CE" & lr)

 Application.ScreenUpdating = False

 For Each c In ceBySel

    If c = "BUY" Or c = "SELL" Then
           c.Resize(1, 3).Copy
         Sheets("Orders").Range("B" & Rows.Count).End(xlUp)(2).PasteSpecial Paste:=xlPasteValues
    End If

 Next
 Application.CutCopyMode = False
 Application.ScreenUpdating = True
 End Sub
 
Upvote 0
Try this.


Rich (BB code):
Option Explicit

 Sub BuyCells()
 Dim c As Range
 Dim ceBySel As Range
 Dim lr As Long

 lr = Cells(Rows.Count, 1).End(xlUp).Row
 Set ceBySel = Range("CE6:CE" & lr)

 Application.ScreenUpdating = False

 For Each c In ceBySel

    If c = "BUY" Or c = "SELL" Then <-Run time error 
           c.Resize(1, 3).Copy
         Sheets("Orders").Range("B" & Rows.Count).End(xlUp)(2).PasteSpecial Paste:=xlPasteValues
    End If


 Next
 Application.CutCopyMode = False
 Application.ScreenUpdating = True
 End Sub

Thank you very much sir
 
Upvote 0
Looks like I missed a small detail on this line.

Change the 1 to 83 and se if that makes a difference.


Code:
 lr = Cells(Rows.Count, [COLOR="#FF0000"]83[/COLOR]).End(xlUp).Row

Howard
 
Upvote 0
The headers on the Orders sheet seem to be in error, should be this, but the code will still work with the faulty headers.

Code:
 Symbol	Action	Quantity	Lmt Price	Gap

Howard
 
Upvote 0
sir ,

Hi, I have a pretty tough request,

What I would like to do is have a button that I could press that once pressed starts an event which copied the all the data in column B into column A exactly 10 seconds later ..!!

i tried this code

but it didn't work

Private Sub CommandButton1_Click()
Dim x As Variant, _
LR As Long

If Range("B1") = "" Then
Range("B:B").Value = Range("A:A").Value
Application.OnTime Now() + TimeValue("00:00:10"), "OnTimeFill", , True
End If
End Sub

Thank you very much ..!!


 
Upvote 0
Copy this to a Standard Module, not the sheet module. I used a Forms button with the Sub TenSec() assigned to it.

The button needs to be on the sheet you want the copy code to run on.

So, if you had a button on three different sheets and TenSec was assigned to each button, the code would work on the sheet of the button clicked and not the other two.

This may not be in best practice of coding. Maybe one of the pros will chime in and make a suggestion.

Howard

Code:
Option Explicit

Sub TenSec()
 'Runs a macro 10 seconds after button click.

Application.OnTime Now + TimeValue("00:00:10"), "AcolToBcol"

End Sub

Sub AcolToBcol()
Dim c As Range
Dim Lc As Long, lr As Long
Dim Brng As Range
Dim lColumn As Long

lr = Cells(Rows.Count, 2).End(xlUp).Row
Set Brng = Range("B1:B" & lr)

For Each c In Brng
  
  If c <> "" Then
     c.Copy c.Offset(, -1)
  End If
  
Next

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,372
Messages
6,124,537
Members
449,169
Latest member
mm424

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