Solved

Save a select cell as a global variable in a worksheet

Posted on 2011-03-11
7
334 Views
Last Modified: 2012-06-21
Excel 2003

I have a spreadsheet with several columns.

In column B..(but not row 1)

When I type a value into


                  Column B
                  MFRNUM....etc..  OTHER COLUMNS HEADERS
ROW 2 ->  33343
ROW 3 ->  4412
ROW 4 ->  32324
ROW 5 ->  555


The current code

processes some code on worksheet change event...

and then in a module I use this code...to select the active cell

Range("B65536").Select
Selection.End(xlUp).Select

So by using the code above : example

If I go back and want to change  ("B3")
and the code above executes
the cell selected  will be ("B5")
I need it to go back to ("B3")


Is this possible?

Thanks
fordraiders













0
Comment
Question by:fordraiders
  • 3
  • 3
7 Comments
 
LVL 13

Expert Comment

by:George K.
ID: 35112388
Why not use: Range("B6").Select

Also have in mind using syntax like $B$3  instead of  B3
0
 
LVL 3

Author Comment

by:fordraiders
ID: 35112425
because, I may want to change ("B2")  I need to go back to  B2..

0
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 35112474
Let's re-frame the objective. When do you want the first free cell in column B to be selected?

Kevin
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 35112509
Try this code. It might work as desired.

Option Explicit

Private mSelect As Boolean

Private Sub Worksheet_Activate()

    mSelect = True

End Sub

Private Sub Worksheet_Change(ByVal Target As Range)

    If mSelect Then
        Range("B65536").End(xlUp).Select
    End If

End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    If Target.Column = 2 And Target.Row <= Range("B65536").End(xlUp).Row Then
        mSelect = False
    Else
        mSelect = True
    End If

End Sub

Kevin
0
 
LVL 3

Author Comment

by:fordraiders
ID: 35112641
zorvek, The first free cell is selected only if the cell below the cell I'm currently in is "free"

example :

If
B5 is where I want to change and the next "free" cell is  
B6 the  go to "B6"
When I type a value:


                  Column B
                  MFRNUM....etc..  OTHER COLUMNS HEADERS
ROW 2 ->  33343
ROW 3 ->  4412
ROW 4 ->  32324
ROW 5 ->  555     <--- TYPING IN HERE AGIN , THEN GO TO B6 because B6 is blank..
ROW 6 ->  blankcell


However,

     Column B
                  MFRNUM....etc..  OTHER COLUMNS HEADERS
ROW 2 ->  33343
ROW 3 ->  4412  <- TYPING IN HERE AGIN , GO BACK TO B3..because I need to make changes in this row..
ROW 4 ->  32324
ROW 5 ->  555    
ROW 6 ->  blankcell

Does this make sense ?

Thanks
fordraiders










0
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 500 total points
ID: 35112709
Try this:

Option Explicit

Private mSelect As Boolean

Private Sub Worksheet_Activate()

    mSelect = True

End Sub

Private Sub Worksheet_Change(ByVal Target As Range)

    If mSelect Then
        Target.Offset(1).Select
    End If

End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    If Target.Column = 2 And Target.Offset(1) = vbNullString Then
        mSelect = True
    Else
        mSelect = False
    End If

End Sub

Kevin
0
 
LVL 3

Author Closing Comment

by:fordraiders
ID: 35156121
Thanks !
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question