Getting a 1004 error but I can't figure out why

skendzie

New Member
Joined
Oct 22, 2014
Messages
6
I have 3 spreadsheets. One form to enter the information, and two different spreadsheets that the information goes into (9月Spares, 9月Project). I have an activex button and two options and to be honest I'm kind of experimenting with them. The code executes if you click the "Enter" Button.

If it Spares is selected, the info should go into the Spares spreadsheet. But I keep getting a application/object defined error when I try select one of the sheet's range. I have no idea why!

Code:
Private Sub Input_Button_Click()
     
     Dim data As Range
     Dim spwksh As Worksheet
     Dim pjwksh As Worksheet
     
               
     Set data = Sheets("Plugin Form").Range("A32:GX32")
     Set spwksh = Sheets("9月Spares")
     Set pjwksh = Sheets("9月Project")
     
     Range("A32").Value = TextBox_Cusname
     Range("C32").Value = TextBox_InvoiceNum
     Range("D32").Value = TextBox_Sales
     Range("F32").Value = TextBox_Cost
     
    If Select_SpareParts.Value = True Then
       
        spwksh.Range("A5").Activate
   
        End If
    
    If Select_Projects.Value = True Then
        
        pjwksh.Range("A5").Activate
        
        End If
        
End Sub

Thanks so much in advance!
 

Some videos you may like

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
17,387
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
You can't activate a range on a sheet that's not the active sheet.
 

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,377
Before you can activate a range on a sheet, the sheet must be selected.

Change this...
spwksh.Range("A5").Activate

To this...
spwksh.Select
Range("A5").Activate



Or use the Aplication.GoTo method
Application.GoTo spwksh.Range("A5")
 

skendzie

New Member
Joined
Oct 22, 2014
Messages
6
I still get the same error :(

Nevermind! The ApplicationGoto worked like a charm! I wonder why the first combination of spwksh.Activate Range("A5").Select doesn't work...
 

Watch MrExcel Video

Forum statistics

Threads
1,122,433
Messages
5,596,098
Members
414,042
Latest member
Swiftkoala

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
Top