Command Button to Copy Cell Ranges

Nade85

New Member
Joined
Sep 13, 2018
Messages
9
Office Version
  1. 2016
Platform
  1. Windows
I am trying to create a simple sheet to copy various ranges of data and move them up one row inside a chart when somebody click on a command button. There are two cells that a command button may pull data from to create a result. I intend for the button to highlight a row at some point but right now I just want it to copy and paste a range of cells up one row then clear out the data left in the bottom row of a chart. I have not coded the clearing of the last row yet because I cannot seem to get paste the "Compile Error: Sub or Function not defined". I have searched and tried multiple different recommendations for doing what I need and am at the point where my brain can't think straight anymore.

Code:
 Private Sub Submit_Click()
 If IsEmpty(Worksheets("Sheet1").Range("h37")) = True And IsEmpty(Worksheets("Sheet1").Range("h35")) = True Then
     'Verifies that a selection was made
     MsgBox "No selection made or date entered."
     Exit Sub
     
 ElseIf IsEmpty(Worksheets("Sheet1").Range("h37")) = False And IsEmpty(Worksheets("Sheet1").Range("h35")) = False Then
     'Verifies that both inputs weren't modified
     MsgBox "Select an existing End Of Period or enter date to create a new one."
     Exit Sub
     
 ElseIf IsEmpty(Worksheets("Sheet1").Range("h37")) = False And IsEmpty(Worksheets("Sheet1").Range("h35")) = True And _
     Not Worksheets("Sheet1").Range("h37").Value = Worksheets("Sheet1").Range("a30").Value Then
     
        'Range Copy and Paste
         
         Worksheets("Sheet1").Range("A5:c30").Copy = Worksheets("Sheet1").Range("a4:c29")
         Worksheets("Sheet1").Range("e5:f30").Copy = Worksheets("Sheet1").Range("e4:f29")
         Worksheets("Sheet1").Range("h5:i30").Copy = Worksheets("Sheet1").Range("h4:i29")
         Worksheets("Sheet1").Range("k5:l30").Copy = Worksheets("Sheet1").Range("k4:l29")
         Worksheets("Sheet1").Range("n5:o30").Copy = Worksheets("Sheet1").Range("n4:o29")
         Worksheets("Sheet1").Range("q5:r30").Copy = Worksheets("Sheet1").Range("q4:r29")
         Worksheets("Sheet1").Range("t5:u30").Copy = Worksheets("Sheet1").Range("t4:u29")
         Worksheets("Sheet1").Range("w5:x30").Copy = Worksheets("Sheet1").Range("w4:x29")
         Worksheets("Sheet1").Range("h37").Copy = Worksheets("Sheet1").Range("a30").PasteSpecial(xlPasteValues)
         Worksheets("Sheet1").Range("h37").ClearContents
         
 End If
 End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try this


Code:
Private Sub Submit_Click()
 If IsEmpty(Worksheets("Sheet1").Range("h37")) = True And IsEmpty(Worksheets("Sheet1").Range("h35")) = True Then
     'Verifies that a selection was made
     MsgBox "No selection made or date entered."
     Exit Sub
     
 ElseIf IsEmpty(Worksheets("Sheet1").Range("h37")) = False And IsEmpty(Worksheets("Sheet1").Range("h35")) = False Then
     'Verifies that both inputs weren't modified
     MsgBox "Select an existing End Of Period or enter date to create a new one."
     Exit Sub
     
 ElseIf IsEmpty(Worksheets("Sheet1").Range("h37")) = False And IsEmpty(Worksheets("Sheet1").Range("h35")) = True And _
     Not Worksheets("Sheet1").Range("h37").Value = Worksheets("Sheet1").Range("a30").Value Then
     
        'Range Copy and Paste
         
         Worksheets("Sheet1").Range("A5:c30").Copy Worksheets("Sheet1").Range("a4:c29")
         Worksheets("Sheet1").Range("e5:f30").Copy Worksheets("Sheet1").Range("e4:f29")
         Worksheets("Sheet1").Range("h5:i30").Copy Worksheets("Sheet1").Range("h4:i29")
         Worksheets("Sheet1").Range("k5:l30").Copy Worksheets("Sheet1").Range("k4:l29")
         Worksheets("Sheet1").Range("n5:o30").Copy Worksheets("Sheet1").Range("n4:o29")
         Worksheets("Sheet1").Range("q5:r30").Copy Worksheets("Sheet1").Range("q4:r29")
         Worksheets("Sheet1").Range("t5:u30").Copy Worksheets("Sheet1").Range("t4:u29")
         Worksheets("Sheet1").Range("w5:x30").Copy Worksheets("Sheet1").Range("w4:x29")
         Worksheets("Sheet1").Range("h37").Copy
         Worksheets("Sheet1").Range("a30").PasteSpecial (xlPasteValues)
         Worksheets("Sheet1").Range("h37").ClearContents         
 End If
 End Sub
 
Upvote 0
Solution
That worked. Finally. I was pretty sure I had tried that configuration but I've rewritten it so many times its hard to keep straight. Appreciate it.
 
Upvote 0
That worked. Finally. I was pretty sure I had tried that configuration but I've rewritten it so many times its hard to keep straight. Appreciate it.

Happy to help,
Regards, JLG
 
Upvote 0

Forum statistics

Threads
1,214,925
Messages
6,122,303
Members
449,078
Latest member
nonnakkong

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