Simple copy paste VBA not working - Help Please

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,347
Office Version
  1. 365
Platform
  1. Windows
This code is supposed to be a simple copy some columns from one tab and paste them on another.
It appears to be functioning, but no values are being pasted.

Code:
Private Sub CommandButton1_Click()
'
'   To unprotect sheet without password
    ActiveSheet.Unprotect
    
'   Copy Over Columns
    Sheets("Basis_of_Estimates").Select
    Columns("A:C").Copy
'    Selection.Copy
    Sheets("Load_Table").Select
    Columns("A:C").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False

        
    Sheets("Basis_of_Estimates").Select
    Columns("D:D").Copy
    Sheets("Load_Table").Select
    Columns("E:E").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False

        
 '   Sheets("Basis_of_Estimates").Select
  '  Columns("W:AC").Copy
   ' Sheets("Load_Table").Select
  '  Columns("F:L").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
   '     :=False, Transpose:=False
   ' Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
   '     SkipBlanks:=False, Transpose:=False

    Application.CutCopyMode = False
'
'   Add Totals
    'Sheets("Load_Table").Select
    'Range("L1").Select
    'ActiveCell.FormulaR1C1 = "=SUM(R[5]C[-6]:R[1014]C)"
    'Range("L2").Select
    'ActiveWindow.SmallScroll Down:=-36
    'ActiveCell.FormulaR1C1 = "=SUM(Basis_of_Estimates!C[-3])"
    'Range("F3:L3").Select
'
'   Pull in PLCs
    'Range("D5").Select
    'ActiveCell.FormulaR1C1 = "PLC"
    'Columns("C:C").Select
    'Selection.Copy
    'Columns("D:D").Select
    'Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
    '    SkipBlanks:=False, Transpose:=False
    'Application.CutCopyMode = False
    'Range("D6").Select
    'ActiveCell.FormulaR1C1 = _
    '    "=INDEX('Function Cross Reference'!C[-1],MATCH(Load_Table!RC[-1],'Function Cross Reference'!C[-2],0))"
    'Range("D6").Select
    'Selection.Copy
    'Range("D6:D1015").Select
    'Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
    '    SkipBlanks:=False, Transpose:=False
    'Range("D6").Select
    'Application.CutCopyMode = False


End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Are all your sheets protected?
Note that your code simply unprotects the sheet that the Command Button is on, and no other sheets.
 
Upvote 0
Actually, non are. I was going to protect that one, but it is currently unprotected.
 
Upvote 0
Trying putting a breakpoint in the first line of your code ( ActiveSheet.Unprotect). then kick the code off.
This will start the code but stop at your breakpoint. Then arrange the windows so you can see both your code and workbook t the same time.
Then, use the F8 key to step through your code one line at a time, while watching what it is doing on your workbook.
Hopefully, in seeing what is actually happening, the issue will become obvious.
 
Upvote 0
Joe;

It going to "Basis...." but its copying the columns on the tab where the ActiveX button is.

Sheets("Basis_of_Estimates").Select
Columns("A:C").Copy

The ActiveX button is on a Tab named "Load_Table" its copying columns A:C on that tab.

Any idea why?
 
Last edited:
Upvote 0
OK this seems to work

Sheets("Basis_of_Estimates").Range("A:C").Copy
Sheets("Load_Table").Select
Columns("A:C").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
 
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

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