compile error expected end of statement

Bandito1

Board Regular
Joined
Oct 18, 2018
Messages
233
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

Found the code below on internet in play text (with no "enters).
I tried to turn it into normale code but i get complile error

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim lRow As Long
Dim lCol As Long
Static lPrevRow As Long

'Restore previous active row to...light blue dotted line
If lPrevRow > 0 Then
Range("A" & lPrevRow, "AK" & lPrevRow).BorderAround Weight:=xlHairline, Color:=RGB(162, 200, 255)
End If
'Highlight current row with a red border
lRow = Target.Row Range("A" & lRow, "AK" & lRow).BorderAround Weight:=xlThin, Color:=RGB(255, 0, 0) lPrevRow = lRow

End Sub

The code should highlight the current row with a red border when a cell is selected
 

Attachments

  • Compile error.png
    Compile error.png
    30.9 KB · Views: 5

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Can you post the link to where you found this code?
 
Upvote 0
The last line should be three lines:

VBA Code:
lRow = Target.Row
Range("A" & lRow, "AK" & lRow).BorderAround Weight:=xlThin, Color:=RGB(255, 0, 0)
lPrevRow = lRow
 
Upvote 0
Solution
The code leaves a blue line when I click somewhere else (duh code comment tells).
How to tell that it shouldn't leave anything but keep the previous layout?
Can't change it into Borderaround = none cause there are some borders. I don't want to remove those.

So when i select cell red border but when i click somewhere else nothing changed
 
Upvote 0

Forum statistics

Threads
1,215,327
Messages
6,124,292
Members
449,149
Latest member
mwdbActuary

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top