How can I skip columns by pressing the tab or arrow key?

sirenetta1

Board Regular
Joined
Feb 11, 2004
Messages
169
I have four column headings and three columns that are used as spacers between those columns. My question is, is there a way that when I press the tab or arrow key, that I can automatically skip the spacer columns? I've tried hiding the spacer columns, but when I print, the print version doesn't show the spacing anymore. Any suggestions?
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Only ways I can think of would involve VBA. If you're comfortable with that then you could (a) use the WS's SelectionChange event handler to test whether you're in a spacer column and have it bump you over one or (b) use the _BeforePrint() event handler to test whether your spacer columns are hidden and if so, unhide them. If you aren't sure how you'd do that, post back indicating what are the "spacer" columns. B, D, F ?
 
Upvote 0
Greg,

Thanks for responding so quickly! I've never used VBA before, but I'd be willing to try to use it if I knew what to do first. I'm not sure if you could do this, but could you e-mail me a .xls example? Yes, the "spacer" columns are just like you said.
 
Upvote 0
another option, although limted by it's own conception, is to keep blank columns locked, unlock other columns (and cells wishing to manipulate). if you've set the protection on the sheet, then allowed users to only select unlocked cells, when you "tab" over, you will skip the blank columns - or locked cells.

HTH
 
Upvote 0
Sirenetta,

Zack's suggestion would certainly be an option. I think you'd need XL2002 to make it work. To implement, I'd use {Ctrl}+{A} to select all cells, then {Ctrl}+{1} (or Format | Cells...), go to the protection tab and unlock all of them, then select columns B, D and F and lock them. Then turn on WS protection checking all boxes except Select Locked Cells. When I tried this, it worked just fine at skipping over the desired columns, but the {Home} key and {Ctrl}+{PgUp}/{PgDown} didn't work like they normally do, which can be a little irritating.

As for a VB-based solution. Right-click on the tab of the worksheet in question. You'll see a popup menu. Pick View Code off that menu and you'll be taken to the VB Editor. Then just paste the code I'll list below into the WS's code module. While this keeps {Home} and {Ctrl}+{PgUp}/{PgDown} working nicely, it does bring user's Security Settings into play. If their security is set to high this won't even run. If it's set to medium they'll get a dialog box asking to Enable Macros each time the WB is opened. (You can overcome that by digitally signing the WB, but that's an additional kettle of fish, so to speak.) Note: I left in a line of code showing another way to test, but the 2nd way may be a little more intuitive to read. So, if you want to try, here is the code:
================================================
<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Worksheet_SelectionChange(<SPAN style="color:#00007F">ByVal</SPAN> Target <SPAN style="color:#00007F">As</SPAN> Range)
    <SPAN style="color:#00007F">Static</SPAN> rngStatTarget <SPAN style="color:#00007F">As</SPAN> Range
    <SPAN style="color:#00007F">Dim</SPAN> intColOffset <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN>
    <SPAN style="color:#00007F">If</SPAN> Target.Count > 1 <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
    
<SPAN style="color:#007F00">'    If (Not CBool(Target.Column Mod 2)) And (Target.Column < 7) Then</SPAN>
    <SPAN style="color:#00007F">If</SPAN> <SPAN style="color:#00007F">Not</SPAN> Intersect(Target, Union([B:B], [D:D], [F:F])) <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN>
        Application.EnableEvents = <SPAN style="color:#00007F">False</SPAN>
        <SPAN style="color:#00007F">If</SPAN> <SPAN style="color:#00007F">Not</SPAN> rngStatTarget <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN>
            <SPAN style="color:#00007F">If</SPAN> rngStatTarget.Column < Target.Column <SPAN style="color:#00007F">Then</SPAN>
                intColOffset = 1
            <SPAN style="color:#00007F">ElseIf</SPAN> Target.Column <> 1 <SPAN style="color:#00007F">Then</SPAN>
                intColOffset = -1
            <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
        <SPAN style="color:#00007F">Else</SPAN>
            intColOffset = 1
        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
        Target.Offset(, intColOffset).Select
        Application.EnableEvents = <SPAN style="color:#00007F">True</SPAN>
    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
    <SPAN style="color:#00007F">Set</SPAN> rngStatTarget = ActiveCell
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>
HTH
 
Upvote 0

Forum statistics

Threads
1,215,026
Messages
6,122,738
Members
449,094
Latest member
dsharae57

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