PDA

View Full Version : Month selection



oleg_v
07-26-2010, 02:54 AM
hi
i have this macro;
Public Sub COPYDT()
Const TEST_COLUMN As String = "Av" '<=== change to suit
Dim i As Long
Dim LastRow As Long
Dim NextRow As Long
NextRow = 4

Dim mnth As Long

With Sheets("oleg")

LastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
For i = 7 To LastRow

If Mid$(.Cells(i, "Av").Value2, 1, 3) = "1CV" Then

NextRow = NextRow + 1
.Cells(i, "b").Resize(, 47).Copy Worksheets("oleg2").Cells(NextRow, "a")
End If
Next i
End With

End Sub

i was wondering can i add to this macro the month selection where the target columns "au" and sheet"oleg"
know the macro copyes the row that according to the target column all the data with first 3 word is"1cv" i want the macro to copy the row that according to the first target column has first 3 words "1cv" and belongs to particular month that will be imput with the input box by number of the month.

thanks

Simon Lloyd
07-26-2010, 03:14 AM
Again without a workbook i have no idea what you really want or are trying to do - please supply a workbook in future!!

Try this:
Public Sub COPYDT()
Const TEST_COLUMN As String = "Av" '<=== change to suit
Dim i As Long
Dim LastRow As Long
Dim NextRow As Long
Dim IB As String
NextRow = 4
Dim mnth As Long
IB = Application.InputBox("Enter month to check for", "Month selection")
With Sheets("oleg")

LastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
For i = 7 To LastRow

If Mid$(.Cells(i, "Av").Value2, 1, 3) = "1CV" And _
Application.WorksheetFunction.Text(.Cells(i, "Av").Offset(0, -1), "mmmm") = LCase(IB) Then

NextRow = NextRow + 1
.Cells(i, "b").Resize(, 47).Copy Worksheets("oleg2").Cells(NextRow, "a")
End If
Next i
End With

End Sub

oleg_v
07-26-2010, 03:16 AM
Thank you very much
i make some thing on my on please tell me if that ok
Public Sub COPYDT()
Const TEST_COLUMN As String = "Av" '<=== change to suit
Dim i As Long
Dim LastRow As Long
Dim NextRow As Long
NextRow = 4

Dim mnth As Long

With Sheets("oleg")
mnth = InputBox("Supply the required month number")


LastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
For i = 7 To LastRow

If Mid$(.Cells(i, "Av").Value2, 1, 3) = "1CV" And Month(.Cells(i, "Au").Value) = mnth Then

NextRow = NextRow + 1
.Cells(i, "b").Resize(, 47).Copy Worksheets("oleg2").Cells(NextRow, "a")
End If
Next i
End With

End Sub

Thanks

Oleg