Show right way the goal

inactiveUser214710

Board Regular
Joined
Apr 27, 2012
Messages
171
Hi every one
I have a userform that has a combobox (combobox1) to choose a specific month and a command button to show all months data in just one listbox(Listbox1). Data combobox1(UserForm_Initialize).

when I choose a month the list box shows the especif month data, but when I click command button the listbox show all the data of all months. This is my goal.

But I have a problem thal is, when I query the form with the sheet 2 open, it works well, but, if the query is made with the sheet 1 open, it don't work well.

That combobox, the data cames from sheet1, but the choose comes from filter in advence data, in sheet 2.

I think the resolution coud be simple but, at the moment, it does not occur to me the change I will have to make. I have no experience in vba reason why I ask for your help. Thank you.
Jdcar
VBA Code:
Private Sub ComboBox1_Change()
'Choose month

Dim i As Integer
Dim Database(1 To 10000, 1 To 7)
Dim My_range As Integer
Dim colum As Byte

On Error Resume Next

ListBox1.ColumnCount = 7
ListBox1.RowSource = "a2:g10000"

'Sheet2 advence data
Sheet2.Range("j2").Value = ComboBox1.Value

    Sheets("Sheet1").Range("A1:G10000").AdvancedFilter Action:=xlFilterCopy, _
        CriteriaRange:=Range("j1:j2"), CopyToRange:=Sheets("Sheet2").Range("a1:g1"), Unique:=False
           
End Sub

Private Sub CommandButton1_Click()
'show data

ComboBox1.Value = Clear

On Error Resume Next

UserForm1.ListBox1.ColumnCount = 7
UserForm1.ListBox1.RowSource = "a2:g10000"

End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Try
VBA Code:
With Sheets("Sheet2")
   ListBox1.List = .Range("A2:G" & .Range("A" & Rows.Count).End(xlUp).Row).Value
End With
 
Upvote 0
Hi
There was any change, that is, when I have sheet 2 open and I call the userform it works well (it responds to my purpose), but if I have it on sheet 1 and call the userform, listbox1 does not respond to the choice of the combobox1.
jdcar
 
Upvote 0
Yes, but what happened when you made the change I suggested?
 
Upvote 0
The criteria range argument is unqualifed.
VBA Code:
Sheets("Sheet1").Range("A1:G10000").AdvancedFilter Action:=xlFilterCopy, _
        CriteriaRange:=Range("j1:j2"), CopyToRange:=Sheets("Sheet2").Range("a1:g1"), Unique:=False

I would guess that the change needed, in addition to Fluff's qualifying the source of the ListBox, was

Rich (BB code):
Sheets("Sheet1").Range("A1:G10000").AdvancedFilter Action:=xlFilterCopy, _
        CriteriaRange:=Sheets("Sheet2").Range("j1:j2"), CopyToRange:=Sheets("Sheet2").Range("a1:g1"), Unique:=False
 
Upvote 0

Forum statistics

Threads
1,215,601
Messages
6,125,758
Members
449,259
Latest member
rehanahmadawan

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