PLwolves87
New Member
- Joined
- Jan 6, 2023
- Messages
- 31
- Office Version
- 365
- Platform
- Windows
Hi,
i have a workbook which has 10 worksheets, i have a userform which has a search button. each worksheet is controlled by a combobox, but the search is also based on a date which is in a text box.
so basically you select the worksheet in the combobox which i have named ("Account2") then you will select a date which is in textbox1 and then press button and then the 8 textboxes display the data.
COMBOBOX is the worksheet it needs to look at for the data
TEXTBOX1 is the date search
i have date in row 1 and row 2 on a test sheet, the problem i have is that its only looking at the first row, it doesn't drop down so when i select a date in TEXTBOX1 which is in row2 im getting the MSGBOX "date not found" but the data is there.. please see below code
Private Sub CommandButton1_Click()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets(Account2.Value)
Dim lr As Long
lr = sh.Range("A" & Rows.Count).End(xlUp).Row
Dim i As Long
If Application.WorksheetFunction.CountIf(sh.Range("A3:AL9999"), Me.TextBox1.Value) = 0 Then
MsgBox "Date not Found", vbOKOnly + vbInformation
Exit Sub
End If
For i = 2 To lr
If sh.Cells(i, "A").Value = Me.TextBox1.Text Then
TextBox2 = sh.Cells(i, "C").Value
TextBox3 = sh.Cells(i, "D").Value
TextBox4 = sh.Cells(i, "E").Value
TextBox5 = sh.Cells(i, "F").Value
TextBox6 = sh.Cells(i, "G").Value
TextBox7 = sh.Cells(i, "H").Value
TextBox8 = sh.Cells(i, "I").Value
TextBox9 = sh.Cells(i, "J").Value
End If
Next i
End Sub
i have a workbook which has 10 worksheets, i have a userform which has a search button. each worksheet is controlled by a combobox, but the search is also based on a date which is in a text box.
so basically you select the worksheet in the combobox which i have named ("Account2") then you will select a date which is in textbox1 and then press button and then the 8 textboxes display the data.
COMBOBOX is the worksheet it needs to look at for the data
TEXTBOX1 is the date search
i have date in row 1 and row 2 on a test sheet, the problem i have is that its only looking at the first row, it doesn't drop down so when i select a date in TEXTBOX1 which is in row2 im getting the MSGBOX "date not found" but the data is there.. please see below code
Private Sub CommandButton1_Click()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets(Account2.Value)
Dim lr As Long
lr = sh.Range("A" & Rows.Count).End(xlUp).Row
Dim i As Long
If Application.WorksheetFunction.CountIf(sh.Range("A3:AL9999"), Me.TextBox1.Value) = 0 Then
MsgBox "Date not Found", vbOKOnly + vbInformation
Exit Sub
End If
For i = 2 To lr
If sh.Cells(i, "A").Value = Me.TextBox1.Text Then
TextBox2 = sh.Cells(i, "C").Value
TextBox3 = sh.Cells(i, "D").Value
TextBox4 = sh.Cells(i, "E").Value
TextBox5 = sh.Cells(i, "F").Value
TextBox6 = sh.Cells(i, "G").Value
TextBox7 = sh.Cells(i, "H").Value
TextBox8 = sh.Cells(i, "I").Value
TextBox9 = sh.Cells(i, "J").Value
End If
Next i
End Sub