Need help copying and pasting values

amert19

New Member
Joined
Jun 2, 2015
Messages
2
Hello. I need help with my code. i'm trying to create a macro were a user clicks a button and have contents of sheet("Pick") be copied and paste values only into a new worksheet that gets created with previous date as name. Below is my code. Can't get past the error message.

Sub CommandButton1_Click()
Dim OrgWs As Worksheet
Dim szToday As String
Set OrgWs = ThisWorkbook.Worksheets("Pick")



If (WeekdayName(Weekday(Date) - 1) = "Tuesday") Then
szToday = Format(Date - 2, "mmm-dd-yy")
ElseIf (WeekdayName(Weekday(Date) - 1) = "Saturday") Then
szToday = Format(Date - 2, "mmm-dd-yy")
Else
szToday = Format(Date - 1, "mmm-dd-yy")
End If

OrgWs.Copy After:=ThisWorkbook.Sheets(Sheets.Count)


Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

ActiveSheet.Name = szToday




End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
I think this may be what you were trying to do.

Code:
Sub TestWSCopy()

  Dim OrgWs As Worksheet
  Dim szToday As String
  Dim NewWS As Worksheet
  
  Set OrgWs = ThisWorkbook.Worksheets("Pick")


  If Weekday(Date, 2) = 2 Then    'Tuesday
    szToday = Format(Date - 2, "mmm-dd-yy")
  ElseIf Weekday(Date, 2) = 6 Then    'Saturday
    szToday = Format(Date - 2, "mmm-dd-yy")
  Else
    szToday = Format(Date - 1, "mmm-dd-yy")
  End If
  
  OrgWs.Copy After:=ThisWorkbook.Sheets(Sheets.Count)
  
  
  ActiveSheet.Name = szToday
  Set NewWS = Sheets(szToday)
  Range(NewWS.Range("A1"), NewWS.Cells.SpecialCells(xlCellTypeLastCell)).Copy
  
  NewWS.Range("A1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
  :=False, Transpose:=False




End Sub

Jeff
 
Upvote 0
It's still giving me an error. It stops and points to the following line:

Range(NewWS.Range("A1"), NewWS.Cells.SpecialCells(xlCellTypeLastCell)).Copy


Almost as if I'm missing a line of code
 
Upvote 0
I tried that code several times on my version of Excel (2010). It didn't fail. Gotta go to work.
 
Upvote 0

Forum statistics

Threads
1,214,630
Messages
6,120,634
Members
448,973
Latest member
ChristineC

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