I have a Excel file (xls) with 20 sheets and like to navigate easily on the same row with the aid of a semi-transparent grey hairline cross. I'm a newbie in VBA and I've spend several hours searching a solution, unfortunately without success at now.
Let's say in B3 there is the number 7 written, in B4 the number 10:
a) if I click on an arbitrary cell, e.g. B3, I'd like to have a hairline cross over column B and row 3
b) if I mark with the mouse the fields B3 and B4, the hairline cross (initially at B3) should disappear, next when I go with the mouse coursor to the bottom right of the cell B4 and drag the "plus"-sign into the next cell B5 Excel automatically should paste the number 13 (difference of 3 added to number 10) in cell B5. The "formula-drag-and-drop" function should also work with formulas. (With most Excel files /Add-Ins I've tried unfortunately this wasn't possible).
Does someone knows an easy and workable solution for aims a) and b)?
EDIT: Usability of other excel functions (e.g. undo and redo) should remain.
put this in ThisWorkbook module
I've assembled a piece of VBA that should match your requirements. Just past the code in ThisWorkbook, it will activate the hairline cross in all the sheets. FYI, the hairline cross is created with a conditional format on the current row/column and updated when the selection changes.
Code to place in ThisWorkbook :
Another solution less prone to issues would be to delete the format conditions for each section change. However it might be less performant.
EDIT2 : Added another version with support for a shortcut (Ctrl+Shif+8):
I will answer part (a), for part (b) since my solution to part (a) is not invasive to any cell's content, it will not affect your drag & drop, copy & paste and etc.
1. Create a blank worksheet and name it "CTRL"
2. Open VBA editor (Alt+F11) and paste this code to
ThisWorkbook
module3. Create two name formula
Click the Name Manager button and then click New.
First name formula is as follow:
Second name formula is as follow:
4. Create a conditional formatting using a formula to determine which cells to format
This, unfortunately, you need to create for each and every sheet.
The formatting rule is as follow:
This is the formula:
The cell format you can choose 10% grey fill and white border on all sides.
And apply the rule to the entire worksheet, i.e. Applies to
=$1:$1048576
.Would you consider using some add-in like rowliner?
Assuming you want this Cross Hair Highlight (CHH) for all your 20 sheets and each sheet retains the cross hair, you will need to place codes in each Worksheet object, and a Normal Module.
The CHH will be applied on the column and row of selected cell except itself. When more than 1 cells are selected, the CHH will be removed.
Codes for each Worksheet Object that features CHH:
Create a new Module, say "CrossHair" and place below code (revised to add borders on cells):
These interactions does not interfere normal Excel features, so second part of (b) is not an issue.
The only issue is if your data is already formatted nicely, this CHH with ruin it.
Sample screenshots:
Note some range (non Table ranges) has yellow filled background which got removed by CHH. It will be very hard to allow restoring them.