Selecting a specific range when selected cell is in a row

Milos

Board Regular
Joined
Aug 28, 2016
Messages
111
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
 

Some videos you may like

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

fhqwgads

Board Regular
Joined
Jul 17, 2018
Messages
173
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
 

Milos

Board Regular
Joined
Aug 28, 2016
Messages
111
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
 

Watch MrExcel Video

Forum statistics

Threads
1,095,395
Messages
5,444,228
Members
405,275
Latest member
RefreshSQL

This Week's Hot Topics

Top