Method of Range object failed Target.Address

BKrukowski

Board Regular
Joined
May 6, 2009
Messages
88
Normally I can figure these errors out but I am stumped. I am getting the dreaded runtime 1004 Method 'Range' of object failed. The issue I am having appears to be that I cannot set a range to the Target when using Worksheet_Change event handler

Here is the VBA:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim MyRange As Range
Dim thisRange As Range
Dim unitCost As Long
Dim contractYr As Integer
contractYr = Range("C2").Value

Set thisRange = Range(Target.Address) //HERE IS THE ISSUE HOW TO SET thisRange so I can go back to it later

MsgBox (thisRange) // this msgbox does not show a range it shows the Target.Value


Set MyRange = Range("A10:A15")
If Intersect(Target, MyRange) Is Nothing Then
Exit Sub
End If
Dim lookUpVal As String
lookUpVal = Target.Value
Worksheets("Sheet2").Activate
Sheets("Sheet2").Range("A4:A21").Select
Selection.Find(lookUpVal).Activate
If contractYr = 2017 Then
    unitCost = ActiveCell.Offset(0, 1).Value
End If
If contractYr = 2018 Then
    
     unitCost = ActiveCell.Offset(0, 2).Value
End If

Worksheets("Sheet1").Activate
Range(thisRange).Activate            // HERE IS THE DEBUG POINTER 
ActiveCell.Offset(0, 4).Value = unitCost
 
End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,215,327
Messages
6,124,280
Members
449,149
Latest member
mwdbActuary

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