+ Reply to Thread
Results 1 to 5 of 5

Copy information from one cell to many cells based on certain criteria

  1. #1
    Registered User
    Join Date
    09-06-2006
    Posts
    8

    Post Copy information from one cell to many cells based on certain criteria

    So here is what I am trying to do. There are two columns (well actually more but I am only concerned with two here). They are a date and mileage and look something like the following.

    Date Mileage
    -----------------
    8/23/06 31
    8/24/06
    8/23/06
    8/25/06 56
    8/24/06 12

    This continues. Basically, there are multiple rows on the sheet that can have the same day. I want to be able to enter the mileage traveled on a certain day and have it automatically fill in that same mileage for all other rows that have the same day.

    The shell would look something like this I would imagine:

    Private Sub Worksheet_Change(ByVal Target As Excel.Range)

    If Target.Column = 5 Then '5 is the column containing the mileage data

    'pseudo code follows

    get the date associated with the row where you just entered mileage

    for each row
    if the date is the same as above
    enter Target.Value into column 5 of that row
    end if
    end for


    End If
    End Sub

    For example, when I enter 31 for 8/23/06 all rows containing 8/23/06 will also get a mileage of 31.

    Help please!

    Thanks.

    Thomas

  2. #2
    Registered User
    Join Date
    09-06-2006
    Posts
    8
    I pretty much figured it out...the code is below. I have run into other problems that I have posted in a new thread.

    Please Login or Register  to view this content.

  3. #3
    Valued Forum Contributor Excelenator's Avatar
    Join Date
    07-25-2006
    Location
    Wantagh, NY
    Posts
    333
    You could also use this code which will execute much faster since it doesn't have to check each value in your table to see if it matches. Autofilter takes care of this.

    Please Login or Register  to view this content.







    Quote Originally Posted by thomasrawley
    I pretty much figured it out...the code is below. I have run into other problems that I have posted in a new thread.

    Please Login or Register  to view this content.
    ---------------------------------------------------
    ONLY APPLIES TO VBA RESPONSES WHERE APPROPRIATE
    To insert code into the VBE (Visual Basic Editor)
    1. Copy the code.
    2. Open workbook to paste code into.
    3. Right click any worksheet tab, select View Code
    4. VBE (Visual Basic Editor) opens to that sheets object
    5. You may change to another sheets object or the This Workbook object by double clicking it in the Project window
    6. In the blank space below the word "General" paste the copied code.

  4. #4
    Registered User
    Join Date
    09-06-2006
    Posts
    8
    Wonderful. Thanks for the code!

    If the user enters a mileage and there is no date in that row, I don't want to do anything. How can I add that functionality.

    Thanks again!

    Thomas

  5. #5
    Valued Forum Contributor Excelenator's Avatar
    Join Date
    07-25-2006
    Location
    Wantagh, NY
    Posts
    333
    Quote Originally Posted by thomasrawley
    Wonderful. Thanks for the code!

    If the user enters a mileage and there is no date in that row, I don't want to do anything. How can I add that functionality.

    Thanks again!

    Thomas
    Insert the red code below

    Please Login or Register  to view this content.

+ 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