|
-
Nov 22nd, 2011, 05:04 AM
#1
Thread Starter
Junior Member
Excel Macro to Highlight Row
Hi,
I would like to set up a right click option to highlight the row i have right clicked on (if that makes sense). I have already set up the right click option and the highlight option but it doesn't work and presents with the error: User-Defined type not defined. Here is the code i am using:
Option Explicit
Private Sub BuildCustomMenu2()
Dim ctrl As CommandBarControl
Dim btn As CommandBarControl
Dim i As Integer
'add a 'popup' control to the cell commandbar (menu)
Set ctrl = Application.CommandBars("Cell").Controls.Add _
(Type:=msoControlPopup, Before:=1)
ctrl.Caption = "Highlight"
For i = 50 To 50 'add a few menu items
'add the submenus
Set btn = ctrl.Controls.Add
btn.Caption = "Highlight Yellow" 'give them a name
btn.OnAction = "HighlightYellow" 'the routine called by the control
Next
End Sub
Private Sub DeleteCustomMenu2()
Dim ctrl As CommandBarControl
'go thru all the cell commandbar controls and delete our menu item
For Each ctrl In Application.CommandBars("Cell").Controls
If ctrl.Caption = "Highlight" Then ctrl.Delete
Next
End Sub
Sub Highlight(ByVal Target As Value)
Dim RngRow As Range
Dim RngFinal As Range
Dim Row As Long
Dim Target As Value
'Cells.Interior.ColorIndex = xlNone
Row = Target.Row
Set RngRow = Range("A " & Row, Target)
Set RngFinal = RngRow
RngFinal.Interior.ColorIndex = 6
End Sub
If anyone could please tell me why i am getting this error and how i can make this work i would be very appreciative.
Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|