VBA - Run-time Error '1004': Application-defined or object defined error

raivyne

New Member
Joined
Jul 29, 2014
Messages
13
Hello, I am working on coding part of a macro that checks for the occurance of a string in another string, and if a match is found it needs to change the I cell value of the relevant row.

I am getting Run-time Error '1004': Application-defined or object defined error on the red portion of the following code (the error handling is intentionally disabled at the moment & the missing Dim statements for R1, R2, rc1, rc2, sh1 and sh4 are elsewhere in the macro):

Code:
Dim anum As String
Dim tick As String
Dim note As String
Dim match As String

Set R2 = Intersect(sh4.Range("A:A"), sh4.UsedRange)

For rc2 = R2.Count To 2 Step -1
    
    anum = sh4.Cells(rc2, 1).Value
    tick = sh4.Cells(rc2, 2).Value
 
    sh1.Activate
    ActiveSheet.Range("A1").AutoFilter Field:=1, Criteria1:=anum
    
    Set R1 = Intersect(sh1.Range("F:F"), sh1.UsedRange)
    
    R1.Select
    Selection.Copy
    sh4.Activate
    Range("J1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    
    Set R1 = Intersect(sh4.Range("J2:J1048576"), sh4.UsedRange)
    
    For rc1 = R1.Count To 1 Step -1
                            
        match = sh4.Cells(rc1, 10).Value
                            
        If InStr(match, tick) > 0 Then [B][COLOR=#ff0000]ActiveSheet.Range(rc2, 8) = "TICKER RESTRICTION"
[/COLOR][/B]     
        'On Error Resume Next
                            
    Next
    
        'On Error Resume Next
Next

I tried using a variable to update the value of the cell. This stopped the error, but the I-cell value doesn't get updated when I know each row of my test spreadsheet should return a value > 0. Here is that code:

Code:
Dim anum As String
Dim tick As String
Dim note As String
Dim match As String

Set R2 = Intersect(sh4.Range("A:A"), sh4.UsedRange)

For rc2 = R2.Count To 2 Step -1
    
    anum = sh4.Cells(rc2, 1).Value
    tick = sh4.Cells(rc2, 2).Value
    note = sh4.Cells(rc2, 8).Value
    
    sh1.Activate
    ActiveSheet.Range("A1").AutoFilter Field:=1, Criteria1:=anum
    
    Set R1 = Intersect(sh1.Range("F:F"), sh1.UsedRange)
    
    R1.Select
    Selection.Copy
    sh4.Activate
    Range("J1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    
    Set R1 = Intersect(sh4.Range("J2:J1048576"), sh4.UsedRange)
    
    For rc1 = R1.Count To 1 Step -1
                            
        match = sh4.Cells(rc1, 10).Value
                            
        If InStr(match, tick) > 0 Then note = "TICKER RESTRICTION"
        
        'On Error Resume Next
                            
    Next
    
        'On Error Resume Next
Next

Can anyone shed some light on what I am doing wrong? Thanks in advance!
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Forum statistics

Threads
1,215,036
Messages
6,122,794
Members
449,095
Latest member
m_smith_solihull

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