Code running on worksheet

asyamonique

Well-known Member
Joined
Jan 29, 2008
Messages
1,286
Office Version
  1. 2013
Platform
  1. Windows
Good Day,
Below code is running at userform but on worksheet module its not running...
What would be the reason.
I simply put on worksheet 2 combo and 1 listbox
Is there anything that I need to add?

Code:
Private Sub CommandButton1_Click()

Dim r As Long, Ac As Long, c As Long
  If ComboBox1.Value <> -1 And ComboBox2.Value <> -1 Then
        ListBox1.Clear
        With Worksheets("Reports").Range("A1:A500")
           ReDim Ray(1 To .Count, 1 To 9)
            For r = 1 To .Rows.Count
               With ListBox1
                    .ColumnCount = 9
                    .ColumnWidths = "0;0;100;100;100;100;100;100;0"
                End With
                If ComboBox1.Value = .Cells(r, 1).Value And ComboBox2.Value = .Cells(r, 2).Value Then
                   c = c + 1
                   For Ac = 1 To 9
                        Ray(c, Ac) = .Cells(r, Ac)
                   Next Ac
                End If
            Next r
        End With
End If
ListBox1.List = Ray


End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Active sheet...
Actually I've fixed but if the column datas one of them has date or number entries it doesn't work...
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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