Select method of Range class failed

akk

New Member
Joined
Mar 19, 2009
Messages
36
Hello,

I have this code in a form, which is designed to populate a combo box with all the values of non-empty rows in a given column.

The problem with this is that a "Runtime Error: 1004
Select method of Range class failed" occurs

Code:
' set variables
Dim wsSheet As Worksheet
Dim rngNext As Range
Dim myRange As Range
Set wsSheet = Worksheets("Staff")
With wsSheet
    Set rngNext = .Range("A65536").End(xlUp).Offset(1, 0)
End With
rngNext.Select
Set myRange = Range("a2", rngNext)
 
'populate Group combobox list
With ComboStaff
    Selection.End(xlUp).Select
    For Each rngNext In myRange
        If rngNext = "" Then
            Selection.End(xlUp).Select
        End If
            If rngNext <> "" Then .AddItem rngNext
        Next rngNext
End With

Could someone please point me in the right direction, as to how to fix this problem.

Thanks
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
You can't select a cell on a sheet unless that sheet is active, but you also don't need to select anything to do this:
Code:
' set variables
Dim wsSheet As Worksheet
Dim rngCell As Range
Dim myRange As Range
Set wsSheet = Worksheets("Staff")
With wsSheet
    Set myRange = .Range("a2", .Range("A65536").End(xlUp))

End With
'populate Group combobox list
With ComboStaff
    For Each rngCell In myRange
        If Len(rngcell.Value) > 0 Then .AddItem rngCell.Value
    Next rngCell
End With
 
Upvote 0

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

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