Consulting

Results 1 to 3 of 3

Thread: Month selection

  1. #1
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location

    Month selection

    hi
    i have this macro;
    [VBA]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[/VBA]

    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

  2. #2
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    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:
    [VBA]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[/VBA]
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  3. #3
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location
    Thank you very much
    i make some thing on my on please tell me if that ok
    [VBA]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[/VBA]

    Thanks

    Oleg

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •