michaeltsmith93

Board Regular
Joined
Sep 29, 2016
Messages
83
For the life of my, I can't figure this out. I'm sure it's obvious. I'm getting a subscript error on the line in red below.

Code:
Sub UpdateWatchlistM()


Dim k1 As Worksheet, k2 As Worksheet
Dim FirstBlankRow As Long, r As Long, StartingRow As Long
Dim ESFound As Range


Set k1 = Worksheets("SubjectSummary")
Set k2 = Worksheets("Watchlist")


        StartingRow = 6
        FirstBlankRow = k2.Cells.Find(what:="*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row + 1
        r = StartingRow
        ExistingSubject = k1.Range("D" & r).Value
                        
        Do While Not ExistingSubject = ""
            'look for existing subject in SubjectSummary
            Set ESFound = k2.Columns("D:D").Find(what:=ExistingSubject, LookIn:=xlValues, lookat:=xlWhole)
            If ESFound Is Nothing Then
                'add info to end of SubjectSummary
                Call AddSubjectWatch(r, FirstBlankRow)
                FirstBlankRow = FirstBlankRow + 1
            Else
                'overwrite existing line of main file
                Call AddSubjectWatch(r, ESFound.Row)
            End If
            r = r + 1
            ExistingSubject = k1.Range("C" & r).Value
        Loop


End Sub
Sub AddSubjectWatch(SearchRow As Long, DestRow As Long)
       
    Dim c As Long
       
    For c = 1 To 4
[COLOR=#ff0000]        Worksheets("Watchlist").Cells(DestRow, c).Value = Worksheets("Subject Detail").Cells(SearchRow, c).Value[/COLOR]
    Next c


        Cells(DestRow, 8).Value = Worksheets("Subject detail").Cells(SearchRow, 8).Value


End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Figured out my problem--the sheet that I'm referring to now is called SubjectSummary, not Subject Detail, as in another use of this code.
 
Upvote 0

Forum statistics

Threads
1,215,183
Messages
6,123,529
Members
449,105
Latest member
syed902

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top