Search code examples
excelvbaeventstarget

Issue with line Target.row


I have a macro which works well. This macro changes the size of the character and the color of the selected cell and when unselecting the cell in order to select a new cell, it comes back to the default parameter of the unselected cell and changes the size of the character and color of the selected cell… Now I would like to extend this macro not only to the new selected cell but also to the full line related to selected cell.

In my VBA code, I tried to modify the code by adding ".Row" to the line: With target So with this modification ,my new line is: With Target.Row Unfortunately when selecting a new cell in my worksheet, I get the following error message: Compile error: With Object must be user-defined type, Object, or Variant

Please find the code of my macro below. Thanks in advance for your help.

Const FontSize As Integer = 12
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
LargeSize = FontSize * 1.2
 With Cells
 .Font.Size = FontSize
.Interior.Color = xlNone      
End With



 With Target.Row
.Font.Size = LargeSize
.Interior.Color = 49407    
End With

End Sub

Solution

  • The Row-property of a Range returns the row number.
    What you need is a Range that contains all cells of a row. You can use Range.EntireRow for that:

     With Target.EntireRow
        .Font.Size = LargeSize
        .Interior.Color = 49407
    End With