MhmdHalawi
New Member
- Joined
- Aug 10, 2018
- Messages
- 6
The code below can search by name or a specific day ( ex: 10-august-2018) but what if i want to search by a month (ex: August) can this be done here ? sheet3.cells(x,1) is for the name column and sheet3.cells(x,3) is for the date column
Code:
Sub Button1_Click()Dim lastrow As Long
Dim count As Integer
Dim n As String
lastrow = Sheet3.Cells(Rows.count, 1).End(xlUp).Row
count = 0
y = 2
a = 2
For a = 2 To lastrow
Sheet4.Cells(a, 1).ClearContents
Sheet4.Cells(a, 2).ClearContents
Sheet4.Cells(a, 3).ClearContents
Next a
n = Sheet4.Range("E1")
For x = 2 To lastrow
If Sheet3.Cells(x, 1) Like "*" & n & "*" Or Sheet3.Cells(x, 3) Like "*" & n & "*" Then
Sheet4.Cells(y, 1) = Sheet3.Cells(x, 1)
Sheet4.Cells(y, 2) = Sheet3.Cells(x, 2)
Sheet4.Cells(y, 3) = Sheet3.Cells(x, 3)
count = count + 1
y = y + 1
End If
Next x
If count = 0 Then
For y = 2 To lastrow
Sheet4.Cells(y, 1).ClearContents
Sheet4.Cells(y, 2).ClearContents
Sheet4.Cells(y, 3).ClearContents
Next y
End If
End Sub