ActiveX Option Button to sort Data in another sheet and update conbobox

NUC_N_FUTS2

New Member
Joined
Nov 8, 2024
Messages
15
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have ActiveX Option Buttons on one Sheet and once clicked, would like to go to another sheet and sort data then update a combobox with the sorted data.
There are 4 Option buttons in a group that will sort the data in another sheet based on option button clicked, and then update the ListFillRange and ComboWidths.

When I click the button, nothing happens.

Here is the code located in Module 1:

VBA Code:
Option Explicit

Private Sub OptPartNo_Click()


Application.ScreenUpdating = True
If OptPartNo.Value = True Then

Sheets("Table").Select
    Range("B4:CG6566").Select
    ActiveWorkbook.Worksheets("Table").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Table").Sort.SortFields.Add2 Key:=Range("D4:D6566" _
        ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Table").Sort
        .SetRange Range("B4:CG6566")
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
   
    Sheets("Sheet1").Select
    
With cmbDatabase
    
   .ListFillRange = "SEARCH"
   .ColumnWidths = "0 pt;0 pt;0 pt;108 pt;144 pt;108 pt;108 pt;49.95"
End With
End If
 Application.ScreenUpdating = True
End Sub

Not sure what i am doing wrong here. I kept screenupdating as True so I can see what is happening. The sort doesn't happen.

Can anyone help?

Thanks in advaice.

Nuc
 
Hi Dante,
I do in fact have a formula that returns "".
I am basically pulling data from other sheets and it will return 0 if I did not include the formula. Is there a work around?
 
Upvote 0

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
I do in fact have a formula that returns ""
These are details that you should include in your original post.

Try the following:

VBA Code:
Private Sub OptPartNo_Click()
  Dim lr1 As Long, lr2 As Long
  Application.ScreenUpdating = False
  If OptPartNo.Value = True Then
    
    With Sheets("Table")
      lr1 = .Range("D" & Rows.Count).End(3).Row
      .Range("B4:CG" & lr1).Sort .Range("D4"), xlDescending, Header:=xlNo
      On Error Resume Next
      lr2 = WorksheetFunction.Match("", .Range("D4:D" & lr1), 0) + 2
      On Error GoTo 0
      If lr2 = 0 Then lr2 = lr1
      
      With .Range("B4:CG" & lr2)
        .Sort .Range("D4"), xlAscending, Header:=xlNo
        cmbDatabase.ListFillRange = .Address(0, 0, external:=True)
        cmbDatabase.ColumnWidths = "0 pt;0 pt;0 pt;108 pt;144 pt;108 pt;108 pt;49.95"
      End With
    End With
    
  End If
  Application.ScreenUpdating = True
End Sub

🫡
 
Upvote 0

Forum statistics

Threads
1,223,577
Messages
6,173,164
Members
452,504
Latest member
frankkeith2233

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