Target.Range

azizrasul

Well-known Member
Joined
Jul 7, 2003
Messages
1,304
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
I have the following code

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.Address = "$C$5" Then
        Call Generate_Newlist
    End If

End Sub

which I want to change to something like

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.Range = Range("StartDate") Then
        Call Generate_Newlist
    End If

End Sub

as the value in C5 may change position to say D5 by a user but if I use the range name ("StartDate") then hopefully the code will still work!

When I use the latter code I get an error (argument not optional) on the .Range bit of

Code:
If Target.Range = Range("StartDate") Then
 
Ruddles, Following statements will show you same info - first cell address:
Code:
[COLOR="Blue"]Sub[/COLOR] RangePermutations()
    MsgBox Selection.Range("A1").Address
    MsgBox Selection.Item(1, 1).Address
    MsgBox Selection(1, 1).Address
    MsgBox Selection.Cells(1, 1).Address
    MsgBox Selection.Cells(1).Address
[COLOR="Blue"]End[/COLOR] [COLOR="Blue"]Sub[/COLOR]
 
Last edited:
Upvote 0

Excel Facts

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

The 2nd range is relative to the first range...

Look at it like this

Range("G10:K20").Range("A1").Address = "$G$10"
Range("G10:K20").Range("C3").Address = "$I$12"
Range("G10:K20").Range("B5:D7").Address = "$H$14:$J&16"


Hope that helps..
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

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