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

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
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,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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