+ Reply to Thread
Results 1 to 5 of 5

Simple toggle Macro

  1. #1
    Forum Contributor
    Join Date
    02-26-2005
    Posts
    175

    Simple toggle Macro

    Hi,
    These two codes do exactly what i want.

    Sub one()
    Range("A1").Select
    End Sub

    Sub two()
    Range("A65536").End(xlUp).Offset(1, 0).Select
    End Sub

    I'm trying to put them into one code which i can attach to
    a button. The result will be a toggle between the two when
    the buttom is clicked.
    I can get one or the other to work but not both. Have tried
    different versions of this with no luck. What am i doing wrong?

    Sub TopBottomToggle()
    If Range("A1").Select = False Then
    Range("A1").Select
    Else
    Range("A65536").End(xlUp).Offset(1, 0).Select
    End If
    End Sub

    Thx
    Dave

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Piranha,

    You needed to include the ActiveCell in your code to tell you which cell was selected in column "A". See the code below...

    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

  3. #3
    Forum Contributor
    Join Date
    06-10-2004
    Location
    India
    Posts
    1,066
    I suppose you are looking for something like this...

    Sub TopBottomToggle()
    If ActiveCell.Address <> "$A$1" Then
    Range("A1").Select
    Else
    Range("A65536").End(xlUp).Offset(1, 0).Select
    End If
    End Sub


    - Mangesh

  4. #4
    Forum Contributor
    Join Date
    02-26-2005
    Posts
    175
    Quote Originally Posted by Leith Ross
    Hello Piranha,

    You needed to include the ActiveCell in your code to tell you which cell was selected in column "A". See the code below...

    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross
    Quote Originally Posted by mangesh_yadav
    I suppose you are looking for something like this...

    Sub TopBottomToggle()
    If ActiveCell.Address <> "$A$1" Then
    Range("A1").Select
    Else
    Range("A65536").End(xlUp).Offset(1, 0).Select
    End If
    End Sub


    - Mangesh
    Leith and Mangesh

    Thanks for your fast responce and the use of your time and brains.

    Lieth, your code does exactly what i described in my question. My question
    however was missing the fact, that the active cell before i click the button,
    will be any where on the sheet. (my fault) I am going to use your code in another applcation

    Mangesh, with your code the begining active cell can be anywhere. This is the one
    i will use in the project i am working on now.

    You guys are both great, thx a lot.
    Dave

  5. #5
    Forum Contributor
    Join Date
    06-10-2004
    Location
    India
    Posts
    1,066
    Thanks for the feedback.

    Mangesh

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1