Error Getting Count In Named Range

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,616
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
The user makes a selection from a userform's combobox control "cbx_league". In testing, the user selects "KWHLB".

VBA Code:
Private Sub cbx_league_Change()
    Dim league As String

    If Not mbevents Then Exit Sub
    mbevents = True
    Chg_League '{frm_chg_3League}*
    'chk_main '{frm_permit}*
    bu_cbx_league = permit.cbx_league.Value
End Sub

The change executes the routine "Chg_League", which defines the ranges "nr_calibre" & "nr_dvsion" which hold contents for userform combobox lists (cbx_calibre and cbx_dvsion respectively)

VBA Code:
Sub Chg_League()

    Dim a1 As Range, a2 As Range
    Dim t As Double
    Dim inc As Double
    Dim mycell As Range
    
    league = permit.cbx_league.Value
    permit.cbx_league.BackColor = vbWhite

    mbevents = False
    
    Select Case league
        'several Case Is ...
        Case Is = "KWHLB"
            'Stop
            Set nr_calibre = ws_lists.Range("G4:G4")
            Set nr_dvsion = ws_lists.Range("H42:H48") 'HOUSE
            t = 2
            bigandbad t '{frm_chg_3League}
        'several Case Is ...       
        Case Else
            MsgBox "No Calibre range available for LEAGUE [" & league & "]", vbCritical, "Error: FUNCTION"
            mbevents = False
            permit.cbx_league.Value = ""
            mbevents = True
            Exit Sub
        End Select
        mbevents = True
        
        If t <> "4" Then ActiveWorkbook.Names.Add Name:="nr_division", RefersTo:=nr_dvsion
        ActiveWorkbook.Names.Add Name:="nr_calibre2", RefersTo:=nr_calibre
End Sub

Rich (BB code):
Sub bigandbad(ByRef t As Double)
                
        Dim mycell As Range
        If t = 1 Then
            'user selects from both calibre and division lists
            'prepare calibre
            If nr_calibre.Count = 1 Then
                permit.cbx_calibre.List = Array(nr_calibre.Value)
            Else
                permit.cbx_calibre.List = nr_calibre.Value
            End If
            permit.cbx_calibre.Enabled = True
            permit.cbx_calibre.BackColor = clr_blue
            'prepare division
            If nr_calibre.Count = 1 Then
                permit.cbx_division.List = Array(nr_division.Value)
            Else
                permit.cbx_division.List = Range("nr_division").Value
            End If
            permit.cbx_division.Enabled = False
            
            chk_main '{frm_permit}*
            customer '{frm_activity_reference}*
                    
        ElseIf t = 3 Then
            'prepare calibre
            If nr_calibre.Count = 1 Then
                permit.cbx_calibre.List = Array(nr_calibre.Value)
            Else
                permit.cbx_calibre.List = nr_calibre.Value
            End If
            permit.cbx_calibre.Enabled = False
            'prepare division
            If nr_calibre.Count = 1 Then
                permit.cbx_division.List = Array(Range("nr_division").Value)
            Else
                permit.cbx_division.List = Range("nr_division").Value
            End If
            permit.cbx_division.Enabled = False
            
            chk_main '{frm_permit}*
            customer '{frm_activity_reference}*
            
        ElseIf t = 2 Then
            'calibre defined, division selectable

            'prepare calibre
            If Range("nr_calibre").Count = 1 Then 
                permit.cbx_calibre.List = Array(Range("nr_calibre").Value)
            Else
                permit.cbx_calibre.List = Range("nr_calibre").Value
            End If
            permit.cbx_calibre.Enabled = False
            'prepare division
            If Range("nr_calibre").Count = 1 Then
                permit.cbx_division.List = Array(Range("nr_division").Value)
            Else
                permit.cbx_division.List = Range("nr_division").Value
            End If
            permit.cbx_division.Enabled = True
            permit.cbx_division.BackColor = clr_blue
            
            chk_main '{frm_permit}*
            customer '{frm_activity_reference}*
        
        Else 't=4
            'variable division based on calibre selection (minor groups with HL & REP)
            If nr_calibre.Count = 1 Then
                permit.cbx_calibre.List = Array(nr_calibre.Value)
            Else
                permit.cbx_calibre.List = nr_calibre.Value
            End If
            permit.cbx_calibre.Enabled = True
            permit.cbx_calibre.BackColor = clr_blue
            permit.cbx_division.BackColor = vbWhite
            permit.cbx_division.Enabled = False
            
            chk_main '{frm_permit}*
            customer '{frm_activity_reference}*

        End If
End Sub

The line above in red stops my procedure with a "Method 'range' of object '_Global' failed.
I'd be very grateful for a solution to this problem.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
As nr_calibre is a Range variable, you need to test:

If nr_calibre.Count = 1 Then ...

As written, your code is looking for a non-existent Excel range called "nr_calibre".
 
Upvote 0
Solution

Forum statistics

Threads
1,224,827
Messages
6,181,197
Members
453,022
Latest member
RobertV1609

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