Compile Error: Sub or Function not defined

FrankMcNally

Board Regular
Joined
Nov 14, 2014
Messages
71
This works:
Code:
 Sub Enter_Click()    
Dim NextRow As Long
    Dim VA_Loop As Range
    Dim VA_Loop_Value As Range
    
    
    Sheets("_AYZ81").Activate
    NextRow = Application.WorksheetFunction.CountA(Range("A:A")) + 1
    Cells(NextRow, 1) = "VA" & VA_Number.Value & ".G" & G_Number
    If VA_Number.Value = 1 Then Cells(NextRow + 3, 4) = "'251-9214-8396-957-000-E"
    If VA_Number.Value = 2 Then Cells(NextRow + 3, 4) = "'251-9214-5235-958-000-E"
    If VA_Number.Value = 8 Then Cells(NextRow + 3, 4) = "'251-9214-5235-956-000-E"
    If VA_Number.Value = 9 Then Cells(NextRow + 3, 4) = "'251-9214-5235-956-000-E"

   Unload Import_Information
End Sub

BUT this does not:

Code:
    Dim NextRow As Long
    Dim VA_Loop As Range
    Dim VA_Loop_Value As Range
    
    
    Sheets("_AYZ81").Activate
    NextRow = Application.WorksheetFunction.CountA(Range("A:A")) + 1
    Cells(NextRow, 1) = "VA" & VA_Number.Value & ".G" & G_Number
    If VA_Number.Value = 1 Then Cells(NextRow + 3, 4) = "'251-9214-8396-957-000-E"
    If VA_Number.Value = 2 Then Cells(NextRow + 3, 4) = "'251-9214-5235-958-000-E"
    If VA_Number.Value = 8 Then Cells(NextRow + 3, 4) = "'251-9214-5235-956-000-E"
    If VA_Number.Value = 9 Then Cells(NextRow + 3, 4) = "'251-9214-5235-956-000-E"

If VA_Number.Value = 7 Then        
           Sheets("Sheet1").Activate
           Set VA_Loop_Value = sheet2.Range("H2:H9")
           For Each VA_Loop In VA_Loop_Value
            If VA_Loop = 13 Then ActiveWorksheets("_AYZ81").Cells(NextRow + 3, 4) = "'251-9214-5232-999-000-E"
            If VA_Loop = 15 Then ActiveWorksheets("_AYZ81").Cells(NextRow + 3, 4) = "'251-9214-5232-999-000-E"
            If VA_Loop = 20 Then ActiveWorksheets("_AYZ81").Cells(NextRow + 3, 4) = "'251-9214-5232-999-000-E"
            If VA_Loop = 30 Then ActiveWorksheets("_AYZ81").Cells(NextRow + 3, 4) = "'251-9214-8704-999-000-E"
            If VA_Loop = 35 Then ActiveWorksheets("_AYZ81").Cells(NextRow + 3, 4) = "'251-9214-8704-999-000-E"
            If VA_Loop = 52 Then ActiveWorksheets("_AYZ81").Cells(NextRow + 3, 4) = "'251-9214-8396-999-000-E"
            If VA_Loop = 60 Then ActiveWorksheets("_AYZ81").Cells(NextRow + 3, 4) = "'251-9214-8415-999-000-E"
            If VA_Loop = 70 Then ActiveWorksheets("_AYZ81").Cells(NextRow + 3, 4) = "'251-9214-8415-999-000-E"
        Next VA_Loop
Unload Import_Information
End Sub

The new code is supposed to read from the range created by:
Code:
ActiveSheet.Range("d2:d65536").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Worksheets("Sheet1").Range("h5"), Unique:=True

Whereas VA_Loop is the number within the Range of VA_Loop_Value and therefore each occurrence should generate a String

I am getting the Error:
Compile Error: Sub or Function not defined

with Sub Enter_Click() highlighted in Yellow
and
If VA_Loop = 13 highlighted in Blue

As always any and all help would be appreciated
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Instead of ActiveWorksheets("_AYZ81"), you need to refer to Worksheets("_AYZ81") or Sheets("_AYZ81").

Once that's fixed, you'll need an End If for this line:

If VA_Number.Value = 7 Then
 
Upvote 0
Instead of ActiveWorksheets("_AYZ81"), you need to refer to Worksheets("_AYZ81") or Sheets("_AYZ81").

Once that's fixed, you'll need an End If for this line:

If VA_Number.Value = 7 Then

Thanks, it worked got ride of the error but it didn't enter any of the strings ("'251-9214-5232-999-000-E"/"'251-9214-5232-999-000-E"/"'251-9214-5232-999-000-E"...etc) on worksheet "_AYZ81"??

Any ideas:confused:
 
Upvote 0

Forum statistics

Threads
1,216,179
Messages
6,129,333
Members
449,502
Latest member
TSH8125

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