Defining Active Cell Location

theteerex

Board Regular
Joined
Mar 2, 2018
Messages
102
In the snippet of code below, what would I have to do to change the way I reference the active cell?


Code:
Private Sub Worksheet_Change(ByVal Target As Range) '_Change  creates the variable as a target, transferred as a value to "ProjectName"
    Dim ans As Integer


[B][COLOR=#ff0000]    If Target.Column = 2 And Target.Row > 1 And Target.Value = "" Then [/COLOR][/B]
How can I change the red to this?
Code:
[COLOR=#008000]    If Worksheets("Projects").Range("Records[OPPORTUNITY]") And Worksheets("Projects").Target.Row > 1 And Target.Value = "" Then[/COLOR]
 
A few questions about your code:
  • Do I still need the
    Code:
    ByVal Target As Range
    ?
If there is no Target, isn't this useless?
Yes you do. There is still a Target, it just doesn't have a 'Value' if there are multiple cells in it. Target is still used in the code

Rich (BB code):
Set Changed = Intersect(Target, Columns(2), Rows("2:" & Rows.Count))


  • Is there some way this sub could have done the same thing without the
    Code:
    _Change
    ?
Yes, but then the code wouldn't automatically fire as soon as you deleted something from column B. You would have to run the macro yourself somehow,
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Peter, I am getting an error due to the undo line in your revised code.

Run-time error 1004
Method 'Undo of object' _Application Failed
 
Upvote 0
Peter, I am getting an error due to the undo line in your revised code.

Run-time error 1004
Method 'Undo of object' _Application Failed
The code is working for me & I have been unable to reproduce that error in my workbook.

Are you using the code exactly as from post 9 or have you modified it or combined it with other code?

Can you describe exactly what you did in your worksheet that triggered the code to produce the error?
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,320
Members
452,635
Latest member
laura12345

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