What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Active Cell in VBA

Active Cell in VBA
Author: Message:
mwe99
Veteran Member
*****

Avatar

Posts: 2514
Reputation: 67
36 / Male / Flag
Joined: Jul 2004
O.P. Active Cell in VBA
Excel VBA,

When a command button is clicked, it puts a number in D11, what code do i use to make it move along to the next cell E11.

tricky part, i need this for all six command buttons when the first one is clicked, it moves to the next cell on any of the buttons
05-15-2005 10:03 PM
Profile PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: Active Cell in VBA
There are many possebilities.

Ranging from the use of the objects: Range(), Cells(), Selection(), Offset(), etc...

The principle is to keep your locations in variables (and update them) and use those variables as your locations in those objects.

I can't give a strait forward solution, as there are so many possebilities to do this...

You should already know that:
* to set a numerical value 123 inside the cell A1 on a worksheet called "mysheet":
    Worksheets("mysheet").Range("A1").Value = 123
* to set a numerical value 123 inside the range A1:H8 on a worksheet called "mysheet":
    Worksheets("mysheet").Range("A1:H8").Value = 123
(this is basic VBA/Excel knowledge you should know before you start programming anything)

From here it is easy to make the location "A1" as a variable...
    Dim mylocation As String
    mylocation = "A1"
    Worksheets("mysheet").Range(mylocation).Value = 123
    mylocation = "A2"
    Worksheets("mysheet").Range(mylocation).Value = 123
    mylocation = "A3"
    Worksheets("mysheet").Range(mylocation).Value = 123

But to change the location you need some things todo and to interpret the alphanumerical data and all. In your case, it is easier to define an offset from the topleft of the location and count upwards from there:

In your global variable space you define an array which will hold all the current locations. You don't need to use an array but the use of an arrray depends on how and what you want to do. And since I have to do with the info you gave me I assume you want to hold all the locations globally and independantly:
    Dim CellLocation(1 to 6) As Integer

In the click procedure of button 1 you need to add something like:
    Worksheets("mysheet").Range("D11").Offset(0, CellLocation(1)).Value = mynumber
    CellLocation(1) = CellLocation(1) + 1

In the click procedure of button 2 you need to add something like:
    Worksheets("mysheet").Range("D12").Offset(0, CellLocation(2)).Value = mynumber
    CellLocation(2) = CellLocation(2) + 1

Etc...

Important part is to use the integrated help function of VBA!!!! Search and read the help for the objects used in this post: Range, Cells, Selection, Offset, Worksheets, etc... For the other things on how to do something (working with variables) you need to learn how to program, this is very hard to explain in 1 post and you're better of getting a book on VBA from your local library.

This post was edited on 05-15-2005 at 11:23 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
05-15-2005 11:20 PM
Profile PM Find Quote Report
mwe99
Veteran Member
*****

Avatar

Posts: 2514
Reputation: 67
36 / Male / Flag
Joined: Jul 2004
O.P. RE: Active Cell in VBA
yeah thanks its for my mastermind game lol

still stuck on the basis but this bit been cleared up thanks :)
05-15-2005 11:33 PM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On