B
Bryand
I am trying to get a vlookup with mouse-over to work, however I am having
difficulty assigning a Global Variable, and cannot identify what variables to
declare.
My situation:
data.xls - Columns A:B hold the vlookup information
report.xls - is the file I want to apply this macro to, so that when I right
click on a value in Column A it will look into the data.xls file and return
the value in a popup.
I need to define the range variable (I assumed the range variable was the
“TheCell†but I also see “DataElements†and “LookupRange†– are these all
variables that need to be defined?) within report.xls. My previous attempt
was:
Sub RVariable()
Dim TheCell As Range
TheCell = A: D
End Sub
I have a feeling I should not be using a sub, as the macro above does not
call to it - I am a novice with VB and usually work backwards from a finished
product so any assistance would be greatly appreciated.
Code taken from previous response:
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, _
Cancel As Boolean)
Dim obj As Object
Set TheCell = Target
For Each obj In Application.CommandBars("cell").Controls
If obj.Tag = "HereIsYourItem" Then obj.Delete
Next obj
If Not Application.Intersect(Target, Range("DataElements")) _
Is Nothing Then
With Application.CommandBars("cell").Controls _
.Add(Type:=msoControlButton, before:=6, _
temporary:=True)
.Caption = "See The Definition"
.OnAction = "HereIsYourMacro"
.Tag = "HereIsYourItem"
End With
End If
End Sub
'In the separate module:
Option Explicit
Public TheCell As Range
Sub HereIsYourMacro()
MsgBox Evaluate("=VLOOKUP(""" & TheCell.Value & """,LookupRange,2)")
End Sub
difficulty assigning a Global Variable, and cannot identify what variables to
declare.
My situation:
data.xls - Columns A:B hold the vlookup information
report.xls - is the file I want to apply this macro to, so that when I right
click on a value in Column A it will look into the data.xls file and return
the value in a popup.
I need to define the range variable (I assumed the range variable was the
“TheCell†but I also see “DataElements†and “LookupRange†– are these all
variables that need to be defined?) within report.xls. My previous attempt
was:
Sub RVariable()
Dim TheCell As Range
TheCell = A: D
End Sub
I have a feeling I should not be using a sub, as the macro above does not
call to it - I am a novice with VB and usually work backwards from a finished
product so any assistance would be greatly appreciated.
Code taken from previous response:
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, _
Cancel As Boolean)
Dim obj As Object
Set TheCell = Target
For Each obj In Application.CommandBars("cell").Controls
If obj.Tag = "HereIsYourItem" Then obj.Delete
Next obj
If Not Application.Intersect(Target, Range("DataElements")) _
Is Nothing Then
With Application.CommandBars("cell").Controls _
.Add(Type:=msoControlButton, before:=6, _
temporary:=True)
.Caption = "See The Definition"
.OnAction = "HereIsYourMacro"
.Tag = "HereIsYourItem"
End With
End If
End Sub
'In the separate module:
Option Explicit
Public TheCell As Range
Sub HereIsYourMacro()
MsgBox Evaluate("=VLOOKUP(""" & TheCell.Value & """,LookupRange,2)")
End Sub