Comparing data on two workbooks: Run-time error 438 - Object does not support this propery or method

raivyne

New Member
Joined
Jul 29, 2014
Messages
13
Hello everyone. I am attempting to write a macro that will check data from two different workbooks and update the H column value of one of the first workbook's sheets when certain criteria is fulfilled (i.e. data for the cells in column A matches, and the data from column B of the first sheet is found in column D of the 2nd workbook).

I am getting run-time error 438 - object doesn't support this propery or method on this line of the code (in red below):

Set R1 = Intersect(sh4.Range("A:A"), sh4.Parent.UsedRange)</SPAN>

Here is the full code:

Code:
    Dim sh1 As Worksheet</SPAN>
    Dim sh4 As Worksheet</SPAN>
       
    Dim R1 As Range</SPAN>
    Dim R2 As Range</SPAN>
    Dim rc1 As Integer</SPAN>
    Dim rc2 As Integer</SPAN>
 
Set sh1 = Workbooks("RESTRC.csv").Worksheets("TICKER")</SPAN>
Set sh4 = Workbooks("MULTIDRIFT.xlsx").Worksheets("TEMP")</SPAN>
 
[COLOR=#ff0000]Set R1 = Intersect(sh4.Range("A:A"), sh4.Parent.UsedRange)[/COLOR]</SPAN>[COLOR=#ff0000]
[/COLOR] 
For rc1 = R1.Count To 1 Step -1</SPAN>
 
On Error Resume Next</SPAN>
 
Set R2 = Intersect(sh1.Range("A:A"), sh1.Parent.UsedRange)</SPAN>
           
For rc2 = R2.Count To 1 Step -1</SPAN>
 
On Error Resume Next</SPAN>
 
If InStr(1, Range(rc2, 4).Value, "*" & " " & Range(rc1, 2).Value & " " & "*") > 0 Then sh4.Range(rc1, 8).Value = "TICKER RESTRICTION"</SPAN>

Next</SPAN>

Next</SPAN>
 
On Error GoTo 0</SPAN>

I am sure that I will have the same issue for the R2 variable set up as well... I just don't understand why VBA doesn't like it. Is anyone able to help out?
 
the parent of sh4 (worksheet) is the workbook, which does not have a property called usedrange, the worksheet does
 
Upvote 0
That makes complete sense. Thank you!

I added the parent because i was getting Run-time error '1004': method 'Intersect' of object '_global' failed. However, I was getting it on the R2 assingment which was previously located directly under the R1 assignment.

I will remove parent again and see what happens. Thanks again!
 
Upvote 0

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