Variable Not Defined

Aviles

Board Regular
Joined
Dec 17, 2008
Messages
173
Office Version
  1. 365
Platform
  1. Windows
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?

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
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Try adding the line in red

Rich (BB code):
Private Sub cmdAddPortfolio_Click()
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
 
    Dim rngPFolios As Range
    Dim LastRow As Long
    Dim NoFolios As Long
    'Displays error messages if fields in user form are left blank
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,798
Members
452,943
Latest member
Newbie4296

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