Edit Existing VBA code

mduntley

Board Regular
Joined
May 23, 2015
Messages
139
Office Version
  1. 365
Platform
  1. Windows
I got a VBA code that I got on the interweb (being funny, I know its internet). I want to have it select only Columns A:BE.

I'm also wondering if it's possible to select a range of cells, such as 7:9, and have the entire row highlighted?
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Posting your code would help with getting you assistance.
 
Upvote 0
Opps, I forgot to do that. My bad, but I did use ChatGPT and I got it to work. The code is this

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Application.ScreenUpdating = False

    ' Check if the selection intersects with columns A to BE
    If Not Intersect(Target, Range("A:BE")) Is Nothing Then
        ' Clear the color of all cells in columns A to BE except for row 1
        Range("A2:BE" & Rows.Count).Interior.ColorIndex = 0
        
        ' Highlight the selected rows within the range A to BE, if not selecting row 1
        If Intersect(Target, Rows(1)) Is Nothing Then
            Range("A" & Target.Row & ":BE" & Target.Row + Target.Rows.Count - 1).Interior.ColorIndex = 8
        End If
    End If

    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,908
Messages
6,175,305
Members
452,633
Latest member
DougMo

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