Tabbing in excel-use VBA

P

Phyllis

I was wondering if you can set tabs in excel to tab to unlocked cells only.
I can't find any information about this but it seems like it should be
possible. I am not using a form, just a spreadsheet. But I have written
alot of VBA code if there is a way to do it that way. ANy ideas.
 
G

Gord Dibben

That is the default behaviour in Excel with unlocked cells in a protected
worksheet.

But only in left to right and top to bottom order.

If your order is other that that.......................

Private Sub Worksheet_Change(ByVal Target As Range)
'Anne Troy's taborder event code
Dim aTabOrd As Variant
Dim i As Long

'Set the tab order of input cells
aTabOrd = Array("A5", "B10", "C5", "A10", "B1", "C3") 'adjust to suit

'Loop through the array of cell address
For i = LBound(aTabOrd) To UBound(aTabOrd)
'If the cell that's changed is in the array
If aTabOrd(i) = Target.Address(0, 0) Then
'If the cell that's changed is the last in the array
If i = UBound(aTabOrd) Then
'Select first cell in the array
Me.Range(aTabOrd(LBound(aTabOrd))).Select
Else
'Select next cell in the array
Me.Range(aTabOrd(i + 1)).Select
End If
End If
Next i

End Sub


Gord Dibben MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top