Solved

Save a select cell as a global variable in a worksheet

Posted on 2011-03-11
7
335 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
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 …
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

838 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