VBA code not working

The FindHeaders Module 17 should find a phrase from Header Names sheet on Net Rate 1 and then also Net Rate 2.

It should return on the NOTES sheet
'Phrase' can be found on Net Rate 1 OR
'Phrase' can not be found on Net Rate 1

but it seems to return a positive "can be found" regardless of whether the phrase is actually there or not.
For instance, it says "Puerto Rico Southbound Priority Overnight (Based on Custom rates [Envelope] [Pak] [Package] )  found on Net Rates 1"  but it really not on the sheet.
Can anyone help? Thanks!
Euro5Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Saqib Husain, SyedEngineerCommented:
Can you upload a sample?
0
Martin LissOlder than dirtCommented:
Euro, whenever possible you should include a workbook in your question so that everyone has a fair chance to answer. In any case I found an error in the code I wrote for you. Replace it with this.

Sub FindHeaders()
Dim cel As Range
Dim wsSummary As Worksheet
Dim wsNR1 As Worksheet
Dim wsNR2 As Worksheet
Dim rngFound As Range
Dim lngNewRow As Long

Set wsSummary = Sheets("Summary")
Set wsNR1 = Sheets("Net Rates 1")
Set wsNR2 = Sheets("Net Rates 2")
 
lngNewRow = wsSummary.Range("A1048576").End(xlUp).Row + 2

For Each cel In Range("Headers")
    With wsNR1
        .Select
        Set rngFound = Selection.Find(What:=cel.Value, After:=ActiveCell, _
            LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
            SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
        If rngFound Is Nothing Then
            wsSummary.Cells(lngNewRow, 1) = cel.Value & " not found on " & wsNR1.Name
            lngNewRow = lngNewRow + 1
        Else
            wsSummary.Cells(lngNewRow, 1) = cel.Value & " found on " & wsNR1.Name
            lngNewRow = lngNewRow + 1
        End If
    End With
    With wsNR2
        .Select
        Set rngFound = Selection.Find(What:=cel.Value, After:=ActiveCell, _
            LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
            SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
        If rngFound Is Nothing Then
            wsSummary.Cells(lngNewRow, 1) = cel.Value & " not found on " & wsNR2.Name
            lngNewRow = lngNewRow + 1
        Else
            wsSummary.Cells(lngNewRow, 1) = cel.Value & " found on " & wsNR2.Name
            lngNewRow = lngNewRow + 1
        End If
    End With
Next
End Sub

Open in new window

0
Euro5Author Commented:
sorry, thought that i did! Must have not completed the attachment process. Ok, will try.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Euro5Author Commented:
@Marty, still does not seem to be working.
For instance, on Net sheet 2 there is "Domestic 2 Day" but the result is:
"Domestic 2 Day not found on Net Rates 2"

not sure if I'm missing something...
notes.xlsm
0
Martin LissOlder than dirtCommented:
Are you sure? Please see my results after clearing everything from row 7 down on the Notes sheet.

Looks OK
0
Euro5Author Commented:
I don't know what I'm missing. I used the same file that I uploaded.
I cleared the rows then ran the macro.
notes.JPG
0
Martin LissOlder than dirtCommented:
Try this. If you still have a notes.xlsm workbook on your pc, rename it. Then download the notes.xlsm workbook you uploaded in post ID: 40833142 and run the FindHeaders macro.
0
Martin LissOlder than dirtCommented:
In addition to my previous post would you be interested in the results looking like this?
Another wayIf so then use this code instead.
Sub FindHeaders()
Dim cel As Range
Dim wsSummary As Worksheet
Dim wsNR1 As Worksheet
Dim wsNR2 As Worksheet
Dim rngFound As Range
Dim lngNewRow As Long
Dim ws As Worksheet

Application.ScreenUpdating = False

Set wsSummary = Sheets("Notes")
Set wsNR1 = Sheets("Net Rates 1")
Set wsNR2 = Sheets("Net Rates 2")

wsSummary.Range("A3,A5").HorizontalAlignment = xlLeft
wsSummary.Range("A7:C7").Font.FontStyle = "Bold"

wsSummary.Cells(lngNewRow, 1) = "Header"
wsSummary.Cells(lngNewRow, 2) = wsNR1.Name
wsSummary.Cells(lngNewRow, 3) = wsNR2.Name

lngNewRow = wsSummary.Range("A1048576").End(xlUp).Row + 2

For Each cel In Range("HeaderNames")
    lngNewRow = lngNewRow + 1
    wsSummary.Cells(lngNewRow, 1) = cel.Value
    With wsNR1
        .Select
        Set rngFound = Selection.Find(What:=cel.Value, After:=ActiveCell, _
            LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
            SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
        If rngFound Is Nothing Then
            wsSummary.Cells(lngNewRow, 2) = "Not found"
        Else
            wsSummary.Cells(lngNewRow, 2) = "Found"
        End If
    End With
    With wsNR2
        .Select
        Set rngFound = Selection.Find(What:=cel.Value, After:=ActiveCell, _
            LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
            SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
        If rngFound Is Nothing Then
            wsSummary.Cells(lngNewRow, 3) = "Not found"
        Else
            wsSummary.Cells(lngNewRow, 3) = "Found"
        End If
    End With
Next

Sheets("Notes").Select
Range("A1:A300").WrapText = False
Columns.AutoFit

Application.ScreenUpdating = True
Sheets("Summary").Activate
End Sub

Open in new window

0
Martin LissOlder than dirtCommented:
Are you talking about line 19 in post D: 40834704? What do you mean by "stuck"?
0
Euro5Author Commented:
I love this version - but I am getting an error at line 19 - any ideas?
0
Euro5Author Commented:
wsSummary.Cells(lngNewRow, 1) = "Header"

header
0
Martin LissOlder than dirtCommented:
Sorry, my fault. I moved as line without testing it again. I corrected that and added line 18 so you can run it without having to delete the previous results.

Sub FindHeaders()
Dim cel As Range
Dim wsSummary As Worksheet
Dim wsNR1 As Worksheet
Dim wsNR2 As Worksheet
Dim rngFound As Range
Dim lngNewRow As Long
Dim ws As Worksheet

Application.ScreenUpdating = False

Set wsSummary = Sheets("Notes")
Set wsNR1 = Sheets("Net Rates 1")
Set wsNR2 = Sheets("Net Rates 2")

' This will delete everything from row 7 on down so you can run
' this macro without having to delete the results of the last time
wsSummary.Range("A7:A" & wsSummary.UsedRange.Rows.Count).EntireRow.Delete

wsSummary.Range("A3,A5").HorizontalAlignment = xlLeft
wsSummary.Range("A7:C7").Font.FontStyle = "Bold"

lngNewRow = wsSummary.Range("A1048576").End(xlUp).Row + 2

wsSummary.Cells(lngNewRow, 1) = "Header"
wsSummary.Cells(lngNewRow, 2) = wsNR1.Name
wsSummary.Cells(lngNewRow, 3) = wsNR2.Name

For Each cel In Range("HeaderNames")
    lngNewRow = lngNewRow + 1
    wsSummary.Cells(lngNewRow, 1) = cel.Value
    With wsNR1
        .Select
        Set rngFound = Selection.Find(What:=cel.Value, After:=ActiveCell, _
            LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
            SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
        If rngFound Is Nothing Then
            wsSummary.Cells(lngNewRow, 2) = "Not found"
        Else
            wsSummary.Cells(lngNewRow, 2) = "Found"
        End If
    End With
    With wsNR2
        .Select
        Set rngFound = Selection.Find(What:=cel.Value, After:=ActiveCell, _
            LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
            SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
        If rngFound Is Nothing Then
            wsSummary.Cells(lngNewRow, 3) = "Not found"
        Else
            wsSummary.Cells(lngNewRow, 3) = "Found"
        End If
    End With
Next

Sheets("Notes").Select
Range("A1:A300").WrapText = False
Columns.AutoFit

Application.ScreenUpdating = True
Sheets("Summary").Activate
End Sub

Open in new window

0
Euro5Author Commented:
No problem at all. Unfortunately, still having some issues though..

Now what I get - removes summary of rows and says no services are found....
Notes
0
Euro5Author Commented:
Here is file I am using.
Rerate-v3.xlsm
0
Martin LissOlder than dirtCommented:
Corrected.
Rerate-v3.xlsm
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Euro5Author Commented:
Excellent solution. Thanks for this.
0
Martin LissOlder than dirtCommented:
You're welcome. Sorry it took so long.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.