Highlight Current Column and Row not working on 2nd worksheet

lebrocoli

New Member
Joined
May 16, 2003
Messages
7
The following vba code works very well on my first worksheet, but does not work on any other worksheet.

My names are defined with 'Workbook' scope.

I took the vba code assigned to the first worksheet and copied it to the second worksheet, 'Within the VBA Editor', but somehow, it does not work.

Do I need to tweak something?

------------------------------------------------------------
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With ThisWorkbook.Names("CurrentRow")
.Name = "CurrentRow"
.RefersToR1C1 = "=" & ActiveCell.Row
End With

With ThisWorkbook.Names("CurrentColumn")
.Name = "CurrentColumn"
.RefersToR1C1 = "=" & ActiveCell.Column
End With
End Sub
--------------------------------------------------------------
 

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.
Hi there. You are trying to define the same name twice. Once the code has been executed on the first worksheet, the names exist, if you actually want the same name to be redefined when you select a different sheet you will need to remove the definition first.
 
Upvote 0
Try this

Create 2 rules on each sheet where you want the operation



Rule 1
Formula:
=ROW()=CELL("row")

Format:
Select your color

Applies to:
=$1:$1048576


Rule 2
=COLUMN()=CELL("column")

Format:
Select your color

Applies to:
=$1:$1048576


--------------------------

Put the following code in Thisworkbook event

Code:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    Calculate
End Sub

ThisWorkbook EVENT
- Open the VB Editor (press Alt + F11).
- Over in the Project Explorer, double click on ThisWorkbook.
- In the white panel that then appears, paste the below code.
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,517
Members
448,968
Latest member
Ajax40

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