Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-23-2012, 03:03 PM
mjlaw mjlaw is offline Excel - move with tab through named range Windows 7 32bit Excel - move with tab through named range Office 2007
Novice
Excel - move with tab through named range
 
Join Date: Mar 2012
Posts: 3
mjlaw is on a distinguished road
Default Excel - move with tab through named range

I have form on an excel spreadsheet. I would like to fill out the cells in a particular order (A1-A7, then B1-B7, then A10-A17, then B10-B17, and so on). Enter always takes me to the next cell below. Tab always takes me to the next cell to the right. I have created a named range and put those cells in order but enter still always goes down and tab always goes right. I thought a named range would work. Any suggestions. I am not opposed to using VBA if anyone can point me in the right direction.



Thanks,

Jason
Reply With Quote
  #2  
Old 03-23-2012, 06:29 PM
JBeaucaire JBeaucaire is offline Excel - move with tab through named range Windows XP Excel - move with tab through named range Office 2003
Advanced Beginner
 
Join Date: Dec 2011
Posts: 51
JBeaucaire is on a distinguished road
Default

It's kludgy, but something like this would be. you can put a Worksheet_SelectionChange event into the sheet module to watch what cell you were in LAST and force Excel to select the next cell in a "Map" you create.

Code:
Option Explicit
Dim Prior As Range

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Prior Is Nothing Then
    Range("A1").Select
    Set Prior = Selection
    Exit Sub
End If

Application.EnableEvents = False
Select Case Prior.Address
    Case "$A$1", "$A$2", "$A$3", "$A$4", "$A$5", "$A$6"
        Prior.Offset(1).Select
        Set Prior = Selection
    Case "$A$7"
        Range("B1").Select
        Set Prior = Selection
    Case "$B$1", "$B$2", "$B$3", "$B$4", "$B$5", "$B$6"
        Prior.Offset(1).Select
        Set Prior = Selection
    Case "$B$7"
        Range("A10").Select
        Set Prior = Selection
    Case "$A$10", "$A$11", "$A$12", "$A$13", "$A$14", "$A$15", "$A$16"
        Prior.Offset(1).Select
        Set Prior = Selection
    Case "$A$17"
        Range("B10").Select
        Set Prior = Selection
    Case "$B$10", "$B$11", "$B$12", "$B$13", "$B$14", "$B$15", "$B$16"
        Prior.Offset(1).Select
        Set Prior = Selection
    Case "$B$17"
        Range("A1").Select
        Set Prior = Selection
End Select
Application.EnableEvents = True

End Sub
Reply With Quote
  #3  
Old 03-24-2012, 09:59 AM
mjlaw mjlaw is offline Excel - move with tab through named range Windows 7 32bit Excel - move with tab through named range Office 2007
Novice
Excel - move with tab through named range
 
Join Date: Mar 2012
Posts: 3
mjlaw is on a distinguished road
Default

Thank you for the response,

That works great but I need to figure out one tweak. Once all the cells have been filled out once this automatically goes back to A1. It creates a loop. I need to be able to select any cell at random. There are other sections of the form that will be filled out afterward and I cannot get to them. Also, when updating information in one of these cells I need to be able to go directly to a cell.

I am very new to VBA. I was thinking an If statement along the lines of If cell B17 is blank, run this code, if cell B17 has any text, do not run this code (B17 will always be filled out by the user). That way when I open the form it will take me through these cells in order but once I have filled them out, I can move to another section or update these without getting stuck in the loop. Any suggestions.

Jason
Reply With Quote
  #4  
Old 03-25-2012, 10:38 PM
JBeaucaire JBeaucaire is offline Excel - move with tab through named range Windows XP Excel - move with tab through named range Office 2003
Advanced Beginner
 
Join Date: Dec 2011
Posts: 51
JBeaucaire is on a distinguished road
Default

Code:
Option Explicit
Dim Prior As Range

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If [B17] <> "" Then Exit Sub
If Prior Is Nothing Then
    Range("A1").Select
    Set Prior = Selection
'etc...
Reply With Quote
  #5  
Old 03-26-2012, 10:40 AM
Catalin.B Catalin.B is offline Excel - move with tab through named range Windows Vista Excel - move with tab through named range Office 2010 32bit
Expert
 
Join Date: May 2011
Location: Iaşi, Romānia
Posts: 386
Catalin.B is on a distinguished road
Default

You can do it by changing options in excel: first, go to office button, Options, Advanced--> Editing options, then , at the first option: After pressing enter , move selection to: and choose Direction: right from list (default is down)
Select the needed ranges, (A1-A7, then B1-B7, then A10-A17, then B10-B17, and so on), go to Home tab, Format-Format cells-Protection and make sure that Locked is unchecked. On the review tab, click on protect sheet, then ok (you can set a password if you want). Now, only those unlocked cells can be edited, and the selection will move to right when pressing enter.
The inconvenient in your case, is that you have to return to previous row after completing the first part of current row.
Reply With Quote
Reply

Tags
named range, vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use named ranges in excel vba? bosve73 Excel Programming 4 01-25-2012 09:26 AM
Excel - move with tab through named range load list box from range in excel Joe Patrick Word VBA 8 06-07-2011 09:31 AM
Excel - move with tab through named range Named range drop-down jgelpi16 Excel 1 04-08-2011 03:08 PM
Can't import home adresses in outlook 2010 from excel named ranges eekie Outlook 0 05-14-2010 02:04 PM
Through VBA, export range from Excel to Word duugg Word VBA 0 08-24-2009 07:50 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:01 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft