Selecting a specific range when selected cell is in a row

Milos

Board Regular
Joined
Aug 28, 2016
Messages
121
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I am just after a small snippet of code to help me accelerate a tedious 'quality assurance' task that is going to take me a couple of days too much data to check off.

I want to be able to quickly select a specific range of cells (cells in columns A - F) when I am in any particular row.

For example:
If I am currently in cell A6 the macro will instantly highlight cells A6:F6 but nothing else.
If I am currently in cell D1 the macro will instantly highlight cells A1:F1 but nothing else.
If I am currently in cell E200 the macro will instantly highlight cells A200:F200 but nothing else etc, etc.

I have been trying with this snippet of code but do not have it quite right.
Code:
[COLOR=#000000][FONT=Consolas]ActiveSheet.Range("A:F").Select[/FONT][/COLOR]

Any help is always appreciated!
Thanks,
Milos
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
try put this in the worksheet code

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Range(Cells(ActiveCell.Row, 1), Cells(ActiveCell.Row, 6)).Select

End Sub

hope that works
 
Upvote 0
Thanks fhqwgads.

Here is my final working code which I have set a keyboard shortcut too. Will make my quality assurance checks slightly less tedious!

Code:
Sub Highlight_Selected_Cells_Yellow()
   
   Application.ScreenUpdating = False
   Dim Rng As Range, cell As Range
   Range(Cells(ActiveCell.Row, 1), Cells(ActiveCell.Row, 6)).Select
   Set Rng = Selection
   For Each cell In Rng
        cell.Interior.ColorIndex = 6
   Next cell
    Range(Cells(ActiveCell.Row, 12), Cells(ActiveCell.Row, 20)).Select
   Set Rng = Selection
   For Each cell In Rng
        cell.Interior.ColorIndex = 6
   Next cell
   Application.ScreenUpdating = True
   
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

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