Runtime error 424 on vba if else

exceljen86

New Member
Joined
Nov 26, 2015
Messages
15
Hi All,

I'm getting runtime error 424 Object not found on the following vba

Code:
Sub Macro2()
'
' Macro2 Macro
'


'
    If ws.input("C3") = "Y" Then
    Sheets(Array("1.02", "1.04")).Select
    
    ElseIf ws.input("C4") = "Y" Then
    Sheets(Array("1.03")).Select
    Sheets("1.04").Activate
    End If
    ActiveWorkbook.ActiveSheet.Copy
End Sub

I know the problem will be extremely simple, but I'm well out of practice and would REALLY appreciate someone's help.

Thanks in advance!!!!!!!
 

bobgentry

New Member
Joined
Nov 25, 2015
Messages
46
looks like ws is undefined.
failing on first line (ws.input) right?
if ws is a sheet (current active sheet?), and C3 the cell you want the value from, try Activesheet.Range("C3").Value
 

exceljen86

New Member
Joined
Nov 26, 2015
Messages
15
Thank you so much!!

I just now need to figure out why it's only copying the first selected sheet :)

#rusty
 

bobgentry

New Member
Joined
Nov 25, 2015
Messages
46
probably because you're only using the copy command on the Activesheet, the current front facing sheet.

rather than use Select and then copy, just use the Copy method directly.

Make sure to use Before or After too, or else the copy will auto-generate a new workbook and paste into that, such as:

Code:
ActiveWorkbook.Worksheets(Array(1, 2)).Copy After:=Worksheets(Worksheets.Count)
worksheets.count is effectively the same as the index of hte last worksheet in the workbook, to always insert at the end.
and i'm using index numbers instead of sheet names, but you already got the array of sheet names thing down.
 

Forum statistics

Threads
1,081,617
Messages
5,360,044
Members
400,565
Latest member
Tommy O

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top