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
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Hi and welcome to MrExcel!

and sort data then update a combobox
Are you sure you want to use a combobox?
We regularly use a combo with a column, although you can use more than one column, the ideal when you manage more than one column is to use a ListBox.

But if you want to use the combo, then add this line:
VBA Code:
.ColumnCount = 8

after this line:
VBA Code:
With cmbDatabase

What happens is that by default the combo has one column, but in the column width you are telling it that the first column is "0 pt", that's why it doesn't show anything in the combobox.

If you decide to switch to listbox, simply change this to the name of the listbox
With cmbDatabase

🤗
 
Upvote 0
Hi and welcome to MrExcel!


Are you sure you want to use a combobox?
We regularly use a combo with a column, although you can use more than one column, the ideal when you manage more than one column is to use a ListBox.

But if you want to use the combo, then add this line:
VBA Code:
.ColumnCount = 8

after this line:
VBA Code:
With cmbDatabase

What happens is that by default the combo has one column, but in the column width you are telling it that the first column is "0 pt", that's why it doesn't show anything in the combobox.

If you decide to switch to listbox, simply change this to the name of the listbox
With cmbDatabase

🤗
 
Upvote 0
Hi Dante,

What is not working is the sort by clicking the option button.

is this something you can assist with?

NUC
 
Upvote 0
is the sort by clicking the option button
When you press the optionbutton, does the macro run?
Do you receive any error messages?

Change this:
VBA Code:
    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

For this:
VBA Code:
    Range("B4:CG6566").Sort Range("D4"), xlAscending, Header:=xlGuess

Try and tell me.
 
Upvote 0
When you press the optionbutton, does the macro run?
Do you receive any error messages?

Change this:
VBA Code:
    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

For this:
VBA Code:
    Range("B4:CG6566").Sort Range("D4"), xlAscending, Header:=xlGuess

Try and tell me.
 
Upvote 0
Hi Dante,

The macro doesn't appear to do anything at all. There are no error messages.

For clarity, The option button is on one sheet and I want to select another sheet, sort the data, then return back to the sheet where the option button is. I left screen updating as true and the macro does not select the other sheet and does not do the sorting. That is why the beginning of the code is to select the "Table" sheet.
 
Upvote 0
When you press the optionbutton, does the macro run?
👆Could you answer that?👆

Try:
VBA Code:
Private Sub OptPartNo_Click()
  Application.ScreenUpdating = False
  If OptPartNo.Value = True Then
    Sheets("Table").Range("B4:CG6566").Sort Sheets("Table").Range("D4"), xlAscending, Header:=xlGuess
        
    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
 
Upvote 0
👆Could you answer that?👆

Try:
VBA Code:
Private Sub OptPartNo_Click()
  Application.ScreenUpdating = False
  If OptPartNo.Value = True Then
    Sheets("Table").Range("B4:CG6566").Sort Sheets("Table").Range("D4"), xlAscending, Header:=xlGuess
       
    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
 
Upvote 0
Hi Dante,

I made the change and the macro still doesn't appear to do anything. The data is not sorted.
 
Upvote 0

Forum statistics

Threads
1,223,532
Messages
6,172,875
Members
452,486
Latest member
standw01

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