+ Reply to Thread
Results 1 to 3 of 3

retrieve month

  1. #1
    Registered User
    Join Date
    02-02-2005
    Posts
    51

    retrieve month

    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

    Please Login or Register  to view this content.

  2. #2
    Forum Contributor
    Join Date
    02-15-2005
    Location
    Blackpool, UK
    Posts
    137
    Not sure, but I think you need a dot before the "Cells" test in the "If" statement.

  3. #3
    Forum Contributor
    Join Date
    02-15-2005
    Location
    Blackpool, UK
    Posts
    137
    Hi benj,

    I have take a little more time to look at the code. I think you need to make the following changes:

    While Not IsEmpty(.Cells(i, 1).Value)

    If Month(.Cells(i, 4).Value) = p And Year(.Cells(i, 4).Value) = q Then
    (Note the dots before CELLS as suggested in previos post)

    End If
    i = i + 1 (otherwise you can get caught in a loop if the selection is False)

    HTH

    Art

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1