+ Reply to Thread
Results 1 to 6 of 6

Select matching cell and insert value 4 cells to the left of selected cell?

Hybrid View

  1. #1
    Registered User
    Join Date
    02-02-2012
    Location
    Canada
    MS-Off Ver
    Excel 2013
    Posts
    42

    Select matching cell and insert value 4 cells to the left of selected cell?

    Hello all,

    This is pulling from something that was already done by walruseggman on the forums. He helped me make a macro that searched for partial matches between two columns in separate different worksheets and copy the interior color from one to the other if there was a match. You can see that post here: Old Postl

    Heres the current code Im using:

    Sub TomToms()
    
    Set ws1 = Worksheets("PO Info Checklist")
    Set ws2 = Worksheets("Closed Jobs List")
    
    Set CheckRange = ws2.Range("A1:A" & ws2.Cells(Rows.Count, "A").End(xlUp).Row)
    Set SearchRange = ws1.Range("J1:J" & ws1.Cells(Rows.Count, "J").End(xlUp).Row)
    
    For Each cell In CheckRange
    SearchItem = "*" & cell.Value & "*"
    Set c = SearchRange.Find(SearchItem)
        If Not c Is Nothing Then c.Interior.Color = cell.Interior.Color 
    Next
    
    End Sub
    Here's what I would like to do. in ws1 column N is a blank column for dates. In ws2 column C has dates filled in. I would like for each match in the previous code to pull the date from column C in ws2 and put it into column N for ws1.

    I tried some stuff on my own, but I kept running into roadblocks

    Any help is appreciated.

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Select matching cell and insert value 4 cells to the left of selected cell?

    Try this:
    Sub TomToms()
    
    Set ws1 = Worksheets("PO Info Checklist")
    Set ws2 = Worksheets("Closed Jobs List")
    
    Set CheckRange = ws2.Range("A1:A" & ws2.Cells(Rows.Count, "A").End(xlUp).Row)
    Set SearchRange = ws1.Range("J1:J" & ws1.Cells(Rows.Count, "J").End(xlUp).Row)
    
    For Each cell In CheckRange
    SearchItem = "*" & cell.Value & "*"
    Set c = SearchRange.Find(SearchItem)
        If Not c Is Nothing Then
            c.Interior.Color = cell.Interior.Color
            cell.Offset(, 13).Value = c.Offset(, -7).Value
        End If
    Next
    
    End Sub

  3. #3
    Registered User
    Join Date
    02-02-2012
    Location
    Canada
    MS-Off Ver
    Excel 2013
    Posts
    42

    Re: Select matching cell and insert value 4 cells to the left of selected cell?

    Thanks for the quick reply, but unfortunately, it doesn't seem to do anything :/ But it might be due to another problem. It looks like my code doesn't actually highlight ALL the rows :/ I'm not sure why.

    I have attached the workbook I'm working with, with all (non important values removed of course) the code is in the mainmodule. If you look at Column J in PO Info Checklist worksheet. You'll see almost right away that for example on Line 23 its highlighted red cause 1117 is highlighted red in the Closed Jobs List but cells 24-28 in column J should also be red cause they are also 1117 but they are not:/

    I'm not sure whats going on there.

    Po Checklist 2.xlsm

  4. #4
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Select matching cell and insert value 4 cells to the left of selected cell?

    Sorry ignore this, can't read! Will come back.

  5. #5
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Select matching cell and insert value 4 cells to the left of selected cell?

    OK, does this work? I need to check which code the formatting should be copied from and which it is going to.
    Sub TomToms()
    
    Set ws1 = Worksheets("PO Info Checklist")
    Set ws2 = Worksheets("Closed Jobs List")
    
    Set CheckRange = ws2.Range("A1:A" & ws2.Cells(Rows.Count, "A").End(xlUp).Row)  'closed
    Set SearchRange = ws1.Range("J1:J" & ws1.Cells(Rows.Count, "J").End(xlUp).Row) 'info
    
    For Each cell In CheckRange
    SearchItem = "*" & cell.Value & "*"
    Set c = SearchRange.Find(SearchItem)
        If Not c Is Nothing Then
            c.Offset(, -9).Resize(, 19).Interior.Color = cell.Interior.Color
            c.Offset(, 4).Value = cell.Offset(, 2).Value
            Set c = Nothing
        End If
    Next
    
    End Sub
    Last edited by StephenR; 11-03-2014 at 10:52 AM.

  6. #6
    Registered User
    Join Date
    02-02-2012
    Location
    Canada
    MS-Off Ver
    Excel 2013
    Posts
    42

    Re: Select matching cell and insert value 4 cells to the left of selected cell?

    Works perfectly, thankyou

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Need MACRO to copy the text in the cell left of first selected cells (a column), paste all
    By joobeng in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-16-2013, 06:42 AM
  2. [SOLVED] Using code to select cells that are two cells to the left of the currently active cell
    By LaffyAffy13 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-25-2013, 01:56 PM
  3. Select a Range of Cells Offset from a Selected Merged cell
    By kelvomatic in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-07-2013, 05:52 PM
  4. Replies: 0
    Last Post: 05-16-2013, 04:39 PM
  5. [SOLVED] Matching cell content against selected cells - not range
    By ghoneim in forum Excel General
    Replies: 7
    Last Post: 05-02-2013, 03:50 AM

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