VBA- Use an event to store a value

kgkev

Well-known Member
Joined
Jun 24, 2008
Messages
1,291
Office Version
  1. 365
Platform
  1. Windows
i am trying to store a value to a global variable using

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
lastvalue.Value = Target.Value
End Sub


lastvalue is declared as a string in a module.

I get a Complile Error - Invalid qualifier.

Any idea what is causing this?

Checked and its not just a spelling mistake.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
grrrrr

This gives a runtime error 13 - type mismatch?
 
Upvote 0
as a test this give the same error

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
MsgBox Target.Value
End Sub
 
Upvote 0
What is the value of Target when that occurs?

Maybe Dim lastval as Variant.
 
Upvote 0
Could be anything other than a formula

Blank, number or text
 
Upvote 0
got it - My cells are merged on quite alot of my sheet.

If there a way to overcome this?
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,253
Members
452,900
Latest member
LisaGo

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