Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Save a select cell as a global variable in a worksheet

Posted on 2011-03-11
7
Medium Priority
?
343 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

963 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