Hello,
I'm using the below code which was working fine up until recently. I'm not sure what I've done but I now get the following error when I run the macro: "Compile Error: Variable Not Defined". It hi-lights the word "NoFolios = " in the code below.
Can some one please tell me what I'm doing wrong?
I'm using the below code which was working fine up until recently. I'm not sure what I've done but I now get the following error when I run the macro: "Compile Error: Variable Not Defined". It hi-lights the word "NoFolios = " in the code below.
Can some one please tell me what I'm doing wrong?
Code:
Private Sub cmdAddPortfolio_Click()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim rngPFolios As Range
Dim LastRow As Long
'Displays error messages if fields in user form are left blank
If txtClientFM.Text = "" Then
frmErrorSix.Show
Exit Sub
End If
If txtNewPortfolio.Text = "" Then
frmErrorSix.Show
Exit Sub
End If
'Displays error message if user enters a code that includes a lower case letter
If txtNewPortfolio.Text <> UCase(txtNewPortfolio.Text) Then
frmErrorFive.Show
Exit Sub
End If
'Displays error if user enters duplicate porftolio codes
With Worksheets("Database")
LastRow = .Range("B" & Rows.Count).End(xlUp).Row
Set rngPFolios = .Range("B1:B" & LastRow)
End With
NoFolios = Application.WorksheetFunction.CountIf(rngPFolios, txtNewPortfolio)
If NoFolios > 0 Then
frmErrorTen.Show
'MsgBox "This Porfolio code already exists."
Exit Sub
Else
Worksheets("Database").Cells(LastRow + 1, 1) = txtClientFM.Text
Worksheets("Database").Cells(LastRow + 1, 2) = txtNewPortfolio.Text
End If