Consulting

Results 1 to 9 of 9

Thread: Solved: Search through range and fill corresponding offset?

  1. #1

    Solved: Search through range and fill corresponding offset?

    Hi all new to the forums, and I need your help!


    I need a code that does the following:

    cycle through a range (m3:m50)

    check the cells for a specific data

    if it is in the cell then populate another range (e3:e50) (the corresponding cell only) with a specific line of text.

    Please help!

  2. #2
    Site Admin VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,005
    Location
    How about this:
    [VBA]
    Sub Fill_Offset()
    Dim Rng As Range, MyCell As Range
    Set Rng = Range("M3:M50")
    For Each MyCell In Rng
    If MyCell.Value = "Fred" Then
    MyCell.Offset(0, -8).Value = "Entry Found"
    End If
    Next MyCell
    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
    i understand till the "fred" part but how can this stick "entry found" in the corresponding cell in range E?

    lets look at it like this:

    range E is blank

    range M has the data

    when Fred is located in M then the program populates the same row in E with whatever text I want (embedded in the program)

    dont i need something to cycle through the E range as the M range then output too it?

    thanks for your help BTW

  4. #4
    Site Admin VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,005
    Location
    Did you run the code in a test workbook? i think not! try it and your questions will be answered.
    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)

  5. #5
    NM you were right I am still a newb lol thx!

  6. #6
    Site Admin VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,005
    Location
    Your welcome!, if your question has been solved please mark it solved using thread tools at the top of this window!
    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)

  7. #7
    one more question, now how would the else if statement work...

    if M doesnt equal fred, then check if it equal to bob if it is equal to bob type entry found2

    thanks

  8. #8
    Site Admin VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,005
    Location
    I could do that for you but just try a little research on Case Select this is better than IF,ElseIf,Else,Then
    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)

  9. #9

Posting Permissions

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