Copy and Paste from one worksheet to another.

Tonkytonk

New Member
Joined
Apr 9, 2020
Messages
7
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi all,

The code I'm about to paste isn't the prettiest but does the job. I created this for another spreadsheet of mine which copied data and transposed it into another table which worked a treat.

The problem I'm currently having is that it will not add the data into the table that I have, or if it does it deletes the data that was just added previously. Any help to a) streamline it or b) get it to copy the data would be awesome.


VBA Code:
'
' CopyData Macro
'

    Dim strRng As String
    Dim WKS As String
        
    WKS = Range("C1").Value
    
'Insert a new row
    Application.ScreenUpdating = False
    Sheets(WKS).Select
    Rows("2:2").Select
    Selection.Insert Shift:=xlDown
    
' copy and paste data
    Sheets("Input").Select
    Range("A4").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    
    Selection.Copy
    Sheets(WKS).Select
    Range("A2").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("A1").Select
    Sheets("Input").Select
    Application.CutCopyMode = False

    
' delete empty row
    Application.ScreenUpdating = False
    Sheets(WKS).Select
    Rows("2:2").Select
    Selection.Delete Shift:=xlUp
    Range("A1").Select
        
' clear data in b6 to b9
    Sheets("Input").Select
    Range("A4").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.ClearContents
    Range("A4").Value = "Add Data Here"
    Range("C1").Value = "Buddy"
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Ok I know why it is overwriting the cells now. because I'm copy over the data.

Now in the worksheet that it is coping to it is a table that has been created using Ctrl T.

When I try to insert the cut cells it says that I can't move the data in the table. Just frustrating that it works for my other table but won't work for this one.
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,582
Members
449,089
Latest member
Motoracer88

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