Run-time error 438 when trying to set a range

szita2000

Board Regular
Joined
Apr 25, 2012
Messages
101
Office Version
  1. 365
Platform
  1. Windows
Hi Guys.

I can't seem to figure this one out.

I am attempting to copy from the workbook containing the macro to another workbook.
For the copy and paste I need to set a range in the target workbook that contains the day numbers on Sheet3 in a named range

It crops out with error "Object doesn't support this property or method" at the line:
Set TargetDays = TargetWorkbook.Sheet3.Range("rngMasterDaysHorizontal")


Wonder if this is because I am trying to set an object in another workbook?

Instead of the copy and paste method I am trying to set the values to the source values.


VBA Code:
Sub openMaster()

    Dim TargetDays As Range
    Dim CorrectColumn As Integer
    Dim Shiftreport As Workbook
    Dim SourceDays As Range
    Dim SourceDAY As Integer        'This will be a column number
    Dim TargetWorkbook As Workbook
   
   
    'Opening the workbook
    Workbooks.Open (Sheet5.Range("rngMasterFilePath").Value)
   
    Set TargetWorkbook = ActiveWorkbook
   
    'Setting the searchrange
    Set TargetDays = TargetWorkbook.Sheet3.Range("rngMasterDaysHorizontal")
    'Finding the correct column
    CorrectColumn = TargetDays.Find(ThisDay).Column
   
    Set Shiftreport = ThisWorkbook
    Set SourceDays = Sheet8.Range("rngOutOutputDaysHorizontal")
    SourceDAY = SourceDays.Find(ThisDay).Column
   
        TargetWorkbook.Sheet3.Cells(11, CorrectColumn).Value = Shiftreport.Sheet8.Cells(20, SourceDAY).Value
        TargetWorkbook.Sheet3.Cells(13, CorrectColumn).Value = Shiftreport.Sheet8.Cells(22, SourceDAY).Value
        TargetWorkbook.Sheet3.Cells(14, CorrectColumn).Value = Shiftreport.Sheet8.Cells(23, SourceDAY).Value
        TargetWorkbook.Sheet3.Cells(15, CorrectColumn).Value = Shiftreport.Sheet8.Cells(24, SourceDAY).Value
End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
You can't directly access a sheet in another workbook using its codename (unless you set a reference between the two and even then you'd access it as a member of the project, not the workbook). Did you mean:

Code:
Set TargetDays = TargetWorkbook.Sheets(Sheet3").Range("rngMasterDaysHorizontal")
 
Upvote 0
Alternatively, since you're using a range name:
Code:
Set TargetDays = TargetWorkbook.Names("rngMasterDaysHorizontal").RefersToRange
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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