Compiler Error | Sub or Function not defined

ramzraja

New Member
Joined
Mar 12, 2016
Messages
6
Hi All,

I am new to the Excel VBA. I am using the below code snippet to validate the excel data set but getting Compiler Error | Sub or Function not defined. Could someone guide me on this issue:

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)


'######################################################################################
'CUST_GRP_NAME Validation Started
'######################################################################################
Activate
Range("A2").Select
exceptionCount = 0
Do Until ActiveCell.Address = "$B$10"
' Check if the CUST_GRP_NAME is Not Null
If IsEmpty(ActiveCell.Value) Then
totalExceptions = 1
exceptionCount = 1
Interior.ColorIndex = 6 'Highlight with Yellow Color
Else
Interior.ColorIndex = 15 'Retain Grey Color
End If
Offset(1, 0).Select
Loop
If exceptionCount = 1 Then
exceptionString = exceptionString + vbCrLf & "- CUST_GRP_NAME Cannot be Empty"
End If
'#######'CUST_GRP_NAME Validation Completed '##############################################


End Sub

Thanks,
Rameez Shaik
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
I take it the Activate line is highlighted?
It needs something with it like the worksheet.
Also the Interior.ColorIndex and Offset also need need a range with them.
 
Last edited:
Upvote 0
Hi All,

I am new to the Excel VBA. I am using the below code snippet to validate the excel data set but getting Compiler Error | Sub or Function not defined. Could someone guide me on this issue:

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
'######################################################################################
'CUST_GRP_NAME Validation Started
'######################################################################################
Activate '[COLOR=#ff0000]delete[/COLOR]
Range("A2").Select
exceptionCount = 0
Do Until ActiveCell.Address = "$B$10"  '[COLOR=#ff0000]change to A[/COLOR]
' Check if the CUST_GRP_NAME is Not Null
If IsEmpty(ActiveCell.Value) Then
totalExceptions = 1
exceptionCount = 1
Interior.ColorIndex = 6 'Highlight with Yellow Color '[COLOR=#ff0000]add activesheet[/COLOR]
Else
Interior.ColorIndex = 15 'Retain Grey Color '[COLOR=#FF0000]add activesheet[/COLOR]
End If
Offset(1, 0).Select '[COLOR=#FF0000]add activesheet[/COLOR]
Loop
If exceptionCount = 1 Then
exceptionString = exceptionString + vbCrLf & "- CUST_GRP_NAME Cannot be Empty"
End If
'#######'CUST_GRP_NAME Validation Completed '##############################################
End Sub

Thanks,
Rameez Shaik

Try with the following code:

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)


    '######################################################################################
    'CUST_GRP_NAME Validation Started
    '######################################################################################
    '
    Range("A2").Select
    exceptionCount = 0
    Do Until ActiveCell.Address = "$[COLOR=#0000ff]A[/COLOR]$10"
        ' Check if the CUST_GRP_NAME is Not Null
        If IsEmpty(ActiveCell.Value) Then
            
            exceptionCount = 1
            [COLOR=#0000ff]ActiveCell[/COLOR].Interior.ColorIndex = 6 'Highlight with Yellow Color
        Else
            [COLOR=#0000ff]ActiveCell[/COLOR].Interior.ColorIndex = 15 'Retain Grey Color
        End If
        [COLOR=#0000ff]ActiveCell[/COLOR].Offset(1, 0).Select
    Loop
    If exceptionCount = 1 Then
        MsgBox "- CUST_GRP_NAME Cannot be Empty"
        Cancel = True

    End If
    '#######'CUST_GRP_NAME Validation Completed '##############################################
End Sub
 
Upvote 0

Forum statistics

Threads
1,217,471
Messages
6,136,850
Members
450,027
Latest member
Apexwolf

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