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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
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,224,862
Messages
6,181,465
Members
453,045
Latest member
Abraxas_X

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