Help With Combox VBA

longytravel

Board Regular
Joined
Aug 2, 2011
Messages
68
Hi,

i have some code that searches by date (text box - command button 1) and project name (combobox1 - command button 3). It takes info from the 'data' sheet to the 'reports' sheet

i now also have a second combo box (command button 7) that i want to use to search

i have copied the vba from the first combobox and just changed things to reflect the different columns but i cant get it to work

it copies over the headers but no detail from underneath.

any ideas?

Thanks as ever

Code:
Private Sub CommandButton1_Click()
    Date1 = CLng(DateValue(Me.Date10.Text))
    Date2 = CLng(DateValue(Me.Date20.Text))
    With Sheets("data")
        lr = .Cells(Rows.Count, "B").End(xlUp).Row
        .Range("B1").AutoFilter
        .Range("B1").AutoFilter Field:=2, Criteria1:=">=" & Date1, Operator:=xlAnd, _
            Criteria2:="<=" & Date2
        .Range("A1:I" & lr).SpecialCells(xlCellTypeVisible).Copy Sheets("reports").Range("B2")
        .AutoFilterMode = False
    End With
 
    Range("A:A").ColumnWidth = 5
    Range("B:B").ColumnWidth = 20
    Range("C:C").ColumnWidth = 10
    Columns("D:I").ColumnWidth = 20
    Range("J:J").ColumnWidth = 10
 
End Sub
 
Private Sub CommandButton3_Click()
    With Sheets("data")
        lr = .Cells(Rows.Count, "A").End(xlUp).Row
        .Range("A1").AutoFilter
        .Range("A1").AutoFilter Field:=1, Criteria1:=Me.ComboBox1
        .Range("A1:I" & lr).SpecialCells(xlCellTypeVisible).Copy Sheets("reports").Range("B2")
        .AutoFilterMode = False
    End With
 
    Range("A:A").ColumnWidth = 5
    Range("B:B").ColumnWidth = 20
    Range("C:C").ColumnWidth = 10
    Columns("D:I").ColumnWidth = 20
    Range("J:J").ColumnWidth = 10
 
End Sub
 
Private Sub CommandButton7_Click()
    With Sheets("data")
        lr = .Cells(Rows.Count, "I").End(xlUp).Row
        .Range("I1").AutoFilter
        .Range("I1").AutoFilter Field:=1, Criteria1:=Me.ComboBox2
        .Range("A1:I" & lr).SpecialCells(xlCellTypeVisible).Copy Sheets("reports").Range("B2")
        .AutoFilterMode = False
    End With
 
    Range("A:A").ColumnWidth = 5
    Range("B:B").ColumnWidth = 20
    Range("C:C").ColumnWidth = 10
    Columns("D:I").ColumnWidth = 20
    Range("J:J").ColumnWidth = 10
 
End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Code:
Private Sub CommandButton7_Click()
    With Sheets("data")
        lr = .Cells(Rows.Count, "I").End(xlUp).Row
        .Range("I1").AutoFilter
        .Range("I1").AutoFilter Field:=[COLOR="Red"]9[/COLOR], Criteria1:=Me.ComboBox2
        .Range("A1:I" & lr).SpecialCells(xlCellTypeVisible).Copy Sheets("reports").Range("B2")
        .AutoFilterMode = False
    End With
 
Upvote 0

Forum statistics

Threads
1,224,568
Messages
6,179,595
Members
452,927
Latest member
whitfieldcraig

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