+ Reply to Thread
Results 1 to 14 of 14

VB Script search within a column in one Wb and find in another WB and Highlight yellow

Hybrid View

DixieDiver VB Script search within a... 10-22-2014, 02:18 PM
JOHN H. DAVIS Re: VB Script search within a... 10-22-2014, 02:29 PM
DixieDiver Re: VB Script search within a... 10-22-2014, 02:43 PM
JOHN H. DAVIS Re: VB Script search within a... 10-22-2014, 03:25 PM
DixieDiver Re: VB Script search within a... 10-22-2014, 03:29 PM
DixieDiver Re: VB Script search within a... 10-22-2014, 03:46 PM
jayesh25 Re: VB Script search within a... 10-22-2014, 04:46 PM
DixieDiver Re: VB Script search within a... 10-22-2014, 05:20 PM
jayesh25 Re: VB Script search within a... 10-22-2014, 05:29 PM
DixieDiver Re: VB Script search within a... 10-22-2014, 05:42 PM
jayesh25 Re: VB Script search within a... 10-22-2014, 05:44 PM
DixieDiver Re: VB Script search within a... 10-23-2014, 09:16 AM
jayesh25 Re: VB Script search within a... 10-23-2014, 02:38 PM
DixieDiver Re: VB Script search within a... 10-23-2014, 02:57 PM
  1. #1
    Registered User
    Join Date
    09-04-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    13

    VB Script search within a column in one Wb and find in another WB and Highlight yellow

    Hi
    I am looking for a way to search all text within each row within one column and find the exact match in another workbook and highlight that cell yellow.

    is there an easy script that can run and complete this quickly. it would save me hours of work.

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VB Script search within a column in one Wb and find in another WB and Highlight yellow

    Maybe:

    Sub DixieDiver()
    Dim x As String
    Dim i As Long
    Dim y As Range
    For i = 2 To Range("A" & Rows.Count).End(3).Row
        x = Range("A" & i).Value
            Set y = Workbooks("Another Workbook.xls").Sheets("Sheet1").Cells.Find(x, LookIn:=xlValues, lookat:=xlWhole)
                If Not y Is Nothing Then
                    Workbooks("Another Workbook.xls").Sheets("Sheet1").Cells(y.Row, y.Column).Interior.ColorIndex = 6
                End If
            Set y = Nothing
    Next i
    
    End Sub

  3. #3
    Registered User
    Join Date
    09-04-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: VB Script search within a column in one Wb and find in another WB and Highlight yellow

    Is something wrong with the way I entered it. I only want to search text in A1:A500 then find each cell within that range in A1:A5000 in the other workbook and highlight it Yellow
    Sub DixieDiver()
    Dim x As String
    Dim i As Long
    Dim y As Range
    For i = 2 To Range("A" & Rows.Count).End(3).Row
        x = Range("A" & i).Value
            Set y = Workbooks("Missing PI Tags 20141021b.xlsx").Sheets("Jacobs").Cells.Find(x, LookIn:=xlValues, lookat:=xlWhole)
                If Not y Is Nothing Then
                    Workbooks("DB (Old App).xlsx").Sheets("DB (Old App)").Cells(y.Row, y.Column).Interior.ColorIndex = 6
                End If
            Set y = Nothing
    Next i
    
    End Sub
    Last edited by DixieDiver; 10-22-2014 at 03:28 PM.

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VB Script search within a column in one Wb and find in another WB and Highlight yellow

    Per Forum Rule No. 3. You must use code tags when posting.

    http://www.excelforum.com/forum-rule...rum-rules.html

    Sub DixieDiver()
    Dim x As String
    Dim i As Long
    Dim y As Range
    Workbooks("DB (Old App).xlsx").Sheets("DB (Old App)").Activate
    For i = 1 To 500
        x = Range("A" & i).Value
            Set y = Workbooks("Missing PI Tags 20141021b.xlsx").Sheets("Jacobs").Columns(1).Find(x, LookIn:=xlValues, lookat:=xlWhole)
                If Not y Is Nothing Then
                    Workbooks("Missing PI Tags 20141021b.xlsx").Sheets("Jacobs").Cells(y.Row, y.Column).Interior.ColorIndex = 6
                End If
            Set y = Nothing
    Next i
    
    End Sub
    Last edited by JOHN H. DAVIS; 10-22-2014 at 03:30 PM.

  5. #5
    Registered User
    Join Date
    09-04-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: VB Script search within a column in one Wb and find in another WB and Highlight yellow

    Sorry i fixed it.

  6. #6
    Registered User
    Join Date
    09-04-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: VB Script search within a column in one Wb and find in another WB and Highlight yellow

    I get an error still. "out of range"
    Sub DixieDiver()
    Dim x As String
    Dim i As Long
    Dim y As Range
    Workbooks("Missing PI Tags 20141021b.xlsx").Sheets("Jacobs").Activate
    For i = 1 To 500
        x = Range("A" & i).Value
            Set y = Workbooks("DB (Old App).xlsx").Sheets("DB (Old App)").Columns(1).Find(x, LookIn:=xlValues, lookat:=xlWhole)
                If Not y Is Nothing Then
                    Workbooks("DB (Old App).xlsx").Sheets("DB (Old App)").Cells(y.Row, y.Column).Interior.ColorIndex = 6
                End If
            Set y = Nothing
    Next i
    
    End Sub

  7. #7
    Registered User
    Join Date
    03-12-2014
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    41

    Re: VB Script search within a column in one Wb and find in another WB and Highlight yellow

    Hi Dixie,

    If your search column for the 2nd workbook is also similar as "A" then try this code.

    If it's a fixed column, however a different one than you can amend "1" to whatever you'd like under "ImportWB"

    Paste in a new module

    Option Explicit
    Option Compare Text
    Sub HighLightText()
    Dim i As Integer, counter As Integer, ExportWb As Object, ImportWb As Object, lr As Range
    i = 1
    counter = 1
    Set ExportWb = Workbooks("DB (Old App).xlsx").Sheets("DB (Old App)").Cells
    Set ImportWb = Workbooks("Missing PI Tags 20141021b.xlsx").Sheets("Jacobs").Cells
    Set lr = Workbooks("Missing PI Tags 20141021b.xlsx").Sheets("Jacobs").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
    Do While i < 501
    Do While counter < lr.Row + 1
    If ExportWb(i, 1).Value = ImportWb(counter, 1).Value Then
    ImportWb(counter, 1).Interior.ColorIndex = 6
    End If
    counter = counter + 1
    Loop
    counter = 1
    i = i + 1
    Loop
    MsgBox ("The task has been completed"), vbInformation
    End Sub
    If you want to search the entire sheet with all the columns then you can use John's Code.

    Just try removing

    Workbooks("Missing PI Tags 20141021b.xlsx").Sheets("Jacobs").Activate

  8. #8
    Registered User
    Join Date
    09-04-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: VB Script search within a column in one Wb and find in another WB and Highlight yellow

    Jayesh25

    your code runs without error, but I still don't see the code highlighting the cells yellow when it finds a match. Just to clarify, in column A1:A500 i have tag names in the missing PI tags workbook. I want to search for those tags in the DB workbook in Column A1:A50000 and highlight the cells yellow when found.

    Thanks for you guy's quick response. Very much appreciated

  9. #9
    Registered User
    Join Date
    03-12-2014
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    41

    Re: VB Script search within a column in one Wb and find in another WB and Highlight yellow

    DixieDiver,

    I had set the workbook names the other way around. Retry the below code? I've changed the route from Missing Tags > DB now

    
    Option Explicit
    Option Compare Text
    Sub HighLightText()
    Dim i As Integer, counter As Integer, ExportWb As Object, ImportWb As Object, lr As Range
    i = 1
    counter = 1
    Set ImportWb = Workbooks("DB (Old App).xlsx").Sheets("DB (Old App)").Cells
    Set ExportWb = Workbooks("Missing PI Tags 20141021b.xlsx").Sheets("Jacobs").Cells
    Set lr = Workbooks("DB (Old App).xlsx").Sheets("DB (Old App)").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
    Do While i < 501
    Do While counter < lr.Row + 1
    If ExportWb(i, 1).Value = ImportWb(counter, 1).Value Then
    ImportWb(counter, 1).Interior.ColorIndex = 6
    End If
    counter = counter + 1
    Loop
    counter = 1
    i = i + 1
    Loop
    MsgBox ("The task has been completed"), vbInformation
    End Sub

  10. #10
    Registered User
    Join Date
    09-04-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: VB Script search within a column in one Wb and find in another WB and Highlight yellow

    Awesome that worked great
    Thank you thank you thank you

  11. #11
    Registered User
    Join Date
    03-12-2014
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    41

    Re: VB Script search within a column in one Wb and find in another WB and Highlight yellow

    Most welcome

  12. #12
    Registered User
    Join Date
    09-04-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: VB Script search within a column in one Wb and find in another WB and Highlight yellow

    Just thought of an enhancement for this code that would be helpful. using the code above how would I also highlight the tags that could not be found Red in the original document "Missing PI Tags 20141021b.xlsx"

  13. #13
    Registered User
    Join Date
    03-12-2014
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    41

    Re: VB Script search within a column in one Wb and find in another WB and Highlight yellow

    Hi Dixie.

    I've made some modifications. Try this?
    Option Explicit
    Option Compare Text
    Sub HighLightText()
    Dim i As Integer, counter As Integer, ExportWb As Object, ImportWb As Object, lr As Range, Foundit as integer
    i = 1
    counter = 1
    Set ImportWb = Workbooks("DB (Old App).xlsx").Sheets("DB (Old App)").Cells
    Set ExportWb = Workbooks("Missing PI Tags 20141021b.xlsx").Sheets("Jacobs").Cells
    Set lr = Workbooks("DB (Old App).xlsx").Sheets("DB (Old App)").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
    Do While i < 501
    Do While counter < lr.Row + 1
    If ExportWb(i, 1).Value = ImportWb(counter, 1).Value Then
    Foundit = 1
    ImportWb(counter, 1).Interior.ColorIndex = 6
    End If
    counter = counter + 1
    Loop
    if Foundit = 1 Then
    ExportWb(i, 1).Interior.ColorIndex = 3
    End If
    Foundit = 0
    counter = 1
    i = i + 1
    Loop
    MsgBox ("The task has been completed"), vbInformation
    End Sub

  14. #14
    Registered User
    Join Date
    09-04-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: VB Script search within a column in one Wb and find in another WB and Highlight yellow

    Worked like champ, just had to change the second if found it =1 to 0

    Thanks again

+ 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] Find number and highlight in yellow
    By Jerry HKA in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 02-10-2014, 04:17 AM
  2. [SOLVED] find last empty cell and highlight yellow
    By James__S in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-06-2014, 03:46 PM
  3. [SOLVED] Highlight Yellow Active Row, PROBLEM: row selected before closing stays yellow
    By NumberCruncher311 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-12-2013, 07:01 PM
  4. Highlight blank cells in yellow.
    By n_lindsey in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-11-2013, 02:17 AM
  5. Macro To find match Value from other clomn and highlight in yellow
    By tariqnaz2005 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-16-2012, 09:42 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