Instructions and Macro Code for Romeo

To use the following code :-

Open the Excel Workbook containing the Report(s)

Open the VBE (Visual Basic Editor) alt+F11

Paste the attached code into an existing Module in the VBE or create a new one

You may have to insert some Blank lines for readability

Go back to the Worksheet

Select View ---> Macros

“Click” on the Macro Name and Select --->Options

No alt text provided for this image

Enter a shortcut key of your choice to start the Macro from the Keyboard

Select OK then Close and Select a Worksheet containing a Report

No alt text provided for this image

Select a Cell within the Report

Type the Shortcut Key combination

No alt text provided for this image

Select a Cell within another Report

Type the Shortcut Key combination

No alt text provided for this image

Have Fun !!Any feedback is welcome.

Macro Code

Sub SelectandFormat()

'Setup Variables

Dim CellRng As Range

Dim ColRng As Range

Dim RowRng As Range

Dim Rowcnt As Long

Dim Colcnt As Long

On Error Resume Next

'If a Table Exists Convert the Table to a Range

ActiveSheet.ListObjects("Table1").Unlist

'Reset the Error Flag

On Error GoTo 0

'Save the Cursor Position in a Range Object

Set CellRng = ActiveCell

'Reset All Background Colors

Cells.Interior.Color = RGB(255, 255, 255)

'Select the Cursor Position

CellRng.Select

With Selection

'Create a Table of the Data

   Selection.CurrentRegion.Select

   ActiveSheet.ListObjects.Add(xlSrcRange, Selection, , xlYes).Name = "Table1"

   Range("Table1[#All]").Select

   ActiveSheet.ListObjects("Table1").TableStyle = ""

   ActiveSheet.ListObjects("Table1").Name = "Table1"

End With

CellRng.Select

'Convert the "Sheet" Column and Row Addresses to "Table" Column and Row Addresses

Rowcnt = (CellRng.Row - Range("Table1").Row) + 1

Colcnt = (CellRng.Column - Range("Table1").Column) + 1

'Setup the Column and Row Ranges within the Table as Objects and set the Colours

Set ColRng = ActiveSheet.ListObjects("Table1").ListColumns(Colcnt).Range

ColRng.Interior.Color = RGB(299, 255, 204)

Set RowRng = ActiveSheet.ListObjects("Table1").ListRows(Rowcnt).Range

RowRng.Interior.Color = RGB(299, 255, 204)

CellRng.Interior.Color = RGB(255, 204, 229)

'Stitch the Ranges Together

Application.Union(CellRng, ColRng, RowRng).Select

 

'Tidy Up

'Remove Table

ActiveSheet.ListObjects("Table1").Unlist

CellRng.Select

 'Reset Objects

Set CellRng = Nothing

Set ColRng = Nothing

Set RowRng = Nothing

End Sub

Thanks Ted for sharing your VBA script. This is definitely comes handy for everyone. I love the way you presented the step by step procedure as this can be easily followed by all levels working in excel VBA. Keep sharing. We are all learning from your articles and tutorials. God speed.

Like
Reply

To view or add a comment, sign in

More articles by Ted Hook

  • Your Privacy - Leaving Apple & Google

    {Save the date} 31 May at 2pm meet Murena team to discover big news! How Murena saves you from digital surveillance?…

  • RIP - Debenhams (and Others) or Why we Losing our High Streets

    In the next two week’s all Debenhams stores in the UK will be history and I guess one of the questions already being…

  • We Need a New Churchill

    Democracy is the chosen political model for many of the Western Countries of the world and it is seen as a good thing…

  • Hospitals - Time to Remove Crown Immunity

    In most “Working” environments in the UK, if a member of the public or a staff member is injured or killed, the “Health…

  • My IR35 Journey

    A while ago whilst working within the “IT” industry, I made a Couple of Decisions that changed my life:- · I started…

  • Today is the day I became older and wiser

    Today is the day I became older and wiser Today is the day when I realised that very few know or care what is happening…

  • Windows Mobile Phone – RIP

    In 2014 I encountered a Windows Mobile Phone with a “Tiles” based user interface and I had to have one. Since then I…

    2 Comments
  • Is it Me - Again ???

    I use the Internet for work and leisure every day and have done so since it has become available to the general public…

  • Google CAPTCHA - is this a “Man-in-the-Middle” Attack?

    In order to showcase my skills and experience on the “Web”, I have created a website using a well-known “Self Build”…

  • What if You Don’t Want Cookies

    Whilst trying to view a web page on the BBC news web site I noticed, (like many web pages I have received recently) a…

Explore content categories