Please see my code below and advise. I am getting the error at the arrow marked steps.
Getting 'Compile Error: Object Required' for the below. And when I remove the 'Set' in the below, I get 'Runtime error 424: Object Required'
Sub Button1_Click()
Dim wb1 As Workbook
Dim wb2 As Workbook
Dim Year As Integer
Dim Month As Integer
Set Month = Val(TextBox2.Text) <---
Set Year = Val(TextBox1.Text) <---
Set wb1 = Workbooks.Open("C:\Users\Sreek\Desktop\Others\Project Files\Macro_Experiment\TCOE Consumption " & Month & Year & ".xlsx")
Set wb2 = Workbooks.Open("C:\Users\Sreek\Desktop\Others\Project Files\Macro_Experiment\TCOE Consumption Staging Sheet " & Month & Year & ".xlsx")
wb1.Sheets("TCOE Cost model Information").Range("A2:E1000000").Copy
wb2.Sheets("TCOE Cost model Information").Activate
Range("A2").Select
ActiveSheet.Paste
Range("A1").Select
wb2.Save
wb1.Close SaveChanges:=True
wb2.Close SaveChanges:=True
MsgBox "TCOE Staging sheet is created"
End Sub
Bookmarks