hi,
how can i write vba code to retrieve the month from a cell that holds a date
the problem is that i'm doing a comparison. if the month of the date in row i is p and year is q, where p n q are pre-defined, then i want to copy row i to another sheet. however, running the code below returns an error of Type Mismatch. I assigned P and Q to be integers. so how do i go abt resolving this problem? any kind souls pls help
With sheetA
i = 1
k = 0
While Not IsEmpty(.Cells(i, 1))
k = k + 1
MsgBox "1st try" & p & " " & r
If Month(Cells(i, 4)) = p And Year(Cells(i, 4)) = q Then
.Range("A" & i & ":I" & i).Copy sheetB.Cells(k, 1)
i = i + 1
End If
Wend
End With
Bookmarks