Solved

Save a select cell as a global variable in a worksheet

Posted on 2011-03-11
7
337 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
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‚Ķ

738 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