Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #6  
Old 04-28-2018, 04:28 PM
Logit Logit is offline VBA highlight the entire row issue Windows 10 VBA highlight the entire row issue Office 2007
Expert
 
Join Date: Jan 2017
Posts: 587
Logit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the rough
Default

.
This should work for you. The macro is pasted in ThisWorkbook module so it affects all
sheets in the workbook. If you want it for only one sheet, you can move the macro into
that sheets module:

Code:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)

    Dim RowShape As Shape
    
    ' ************************************************
    ' Check if entire rows are selected
    ' If they are then hide the shapes
    ' ************************************************
    
    If Target.Address = Selection.EntireRow.Address Then
    
        'If error occurs because shape does not exist, ignore the error
        On Error Resume Next
        
        Sh.Shapes("SelectedRow").Visible = msoFalse
        
        'Return error handling to Excel
        On Error GoTo 0
        
        Exit Sub
        
    End If
    
    If Target.Address = Selection.EntireColumn.Address Then
    
        'If error occurs because shape does not exist, ignore the error
        On Error Resume Next
        
        Sh.Shapes("SelectedCol").Visible = msoFalse
        Sh.Shapes("SelectedRow").Visible = msoFalse
        
        'Return error handling to Excel
        On Error GoTo 0
        
        Exit Sub
        
    End If
    
    
    ' Set RowShape to be the SelectedRow
    On Error Resume Next
    Set RowShape = Sh.Shapes("SelectedRow")
    On Error GoTo 0
     
    'If RowShape doesn't exist, then create it
    If RowShape Is Nothing Then
        
        Sh.Shapes.AddShape(msoShapeRectangle, 1, 1, 1, 1).Select
                
        With Selection.ShapeRange
    
            .Fill.Visible = msoFalse ' Remove any fill color
            
            .Name = "SelectedRow"
            
            .Line.Weight = 2 ' Set line thickness e.g. 1, 1.5, 2 etc
            
            .Line.ForeColor.RGB = RGB(146, 208, 80) ' Light Green.
            'Can use vbBlack, vbWhite, vbRed, vbGreen, vbBlue , vbYellow, vbMagenta, vbCyan
            
            'DashStyle = msoLineDash
            ' Can use : msoLineSolid, msoLineSysDot, msoLineSysDash, msoLineDash, msoLineDashDot, msoLineLongDash, msoLineLongDashDot, msoLineLongDashDotDot
            ' Default is msoLineSolid and does not need to be specified
        
        End With
    
    End If
    
    ' ************************************************
    ' Move the SelectedRow shape
    ' ************************************************
    
    With Sh.Shapes("SelectedRow")
    
        .Visible = msoTrue 'Make sure it is visible, it may have been hidden by previous selection
        .Top = Target.Top
        .Left = ActiveWindow.VisibleRange.Left
        .Width = ActiveWindow.VisibleRange.Width
        .Height = Target.Height
              
    End With
    
    Target.Select
    
End Sub
Attached Files
File Type: xlsm worbook-highlight-test.xlsm (18.7 KB, 13 views)
Reply With Quote
 

Tags
highligh, highlight row, vba code



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA highlight the entire row issue highlight the entire row of current cell Joanne Excel 32 05-20-2017 07:30 AM
VBA highlight the entire row issue issue with highlight macro word 2010 jamesnavoy Word VBA 2 01-29-2017 08:32 AM
PDF Conversion Issue - Background Tiled Image Size Issue dustpie Word 1 10-23-2016 07:33 PM
VBA highlight the entire row issue Excel 2007, highlight entire row based on data found in one cell MSofficeBLUE Excel 2 10-15-2013 09:51 PM
find - reading highlight - highlight all / highlight doesn't stick when saved bobk544 Word 3 04-15-2009 03:31 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:34 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft