D
dareks
Hi all,
I am trying to create a routine in VBA using which I should be able to
do the following:
- Lets say I have 10 column headers
- They have long descripotions (e.g. "Time spent on.....") but a short
header name (e.g. TM1).
- The descriptions in the corresponding columns in a different row
(hidden)
I was to be able to display a comment with the appropriate text
whenever the user clicks on a header cell.
I am half way there. Code attached: What I can't figure out is how to
return the position of the cell that the user selects so that I can
refer to the right text for the comment. Any help is highly
appreciated.
Code-
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim newtext$
Dim Addr$
Dim RangeToCheck As Range
Dim RangeComment As Range
Dim isect As Range
Dim intRow As Integer
Dim intCol As Integer
If Target.Cells.Count > 1 Then
Exit Sub
Set RangeToCheck = ThisWorkbook.Sheets("Rep Data").Range("headers")
RangeComment = ThisWorkbook.Sheets("Rep Data").Range("headertext")
Set isect = Application.Intersect(Target, RangeToCheck)
If isect Is Nothing Then Exit Sub
Addr = isect.Address
'intCol = isect.Row
ThisWorkbook.Sheets("Rep Data").Range("row").Value = Addr
'ThisWorkbook.Sheets("Rep Data").Range("col").Value = intCol
'newtext = RangeComment.(intCol).Value
'isect.Comment.Text newtext
End If
End Sub
I am trying to create a routine in VBA using which I should be able to
do the following:
- Lets say I have 10 column headers
- They have long descripotions (e.g. "Time spent on.....") but a short
header name (e.g. TM1).
- The descriptions in the corresponding columns in a different row
(hidden)
I was to be able to display a comment with the appropriate text
whenever the user clicks on a header cell.
I am half way there. Code attached: What I can't figure out is how to
return the position of the cell that the user selects so that I can
refer to the right text for the comment. Any help is highly
appreciated.
Code-
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim newtext$
Dim Addr$
Dim RangeToCheck As Range
Dim RangeComment As Range
Dim isect As Range
Dim intRow As Integer
Dim intCol As Integer
If Target.Cells.Count > 1 Then
Exit Sub
Set RangeToCheck = ThisWorkbook.Sheets("Rep Data").Range("headers")
RangeComment = ThisWorkbook.Sheets("Rep Data").Range("headertext")
Set isect = Application.Intersect(Target, RangeToCheck)
If isect Is Nothing Then Exit Sub
Addr = isect.Address
'intCol = isect.Row
ThisWorkbook.Sheets("Rep Data").Range("row").Value = Addr
'ThisWorkbook.Sheets("Rep Data").Range("col").Value = intCol
'newtext = RangeComment.(intCol).Value
'isect.Comment.Text newtext
End If
End Sub