Consulting

Results 1 to 7 of 7

Thread: Wait for a cell to be selected...

  1. #1

    Wait for a cell to be selected...

    Hi all,

    I have a userform with a CMd button, when I click on this button, it is supposed to activate sheet "sheet1" and I would like my code to wait there until any other cell has been selected( By default there is always one cell selected), so I would like my code to stay there until another cell has been selected.

    Any ideas on how to do this?

    Many thanks,
    JC

  2. #2
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    When you initialise your userform capture the address of the activecell, if your code (which you haven't supplied) selects a cell then you can use a variable to assign that address and check the activecell against it:[VBA]Dim MyCell As String
    'your code
    Range("A1").select
    MyCell = Activecell.Address
    'your code to do something
    'more code
    'now the check
    If Activecell.Address <> MyCell Then
    'rest of your code to run
    Else
    'do something else
    MsgBox "You haven't changed cells"
    End If[/VBA]
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  3. #3
    Hi again.

    This is my code with your suggested code embedded already.

    [VBA]
    Private ub Cmd_Overview_Click()
    Dim Sheet_Name As String
    Dim MyCell As String

    Sheet_Name = ActiveSheet.Name
    Sheets("PB4A_2010").Activate
    ThisWorkbook.Sheets("PB4A_2010").Range("A1").Select

    MyCell = ActiveCell.Address
    If ActiveCell.Address <> MyCell Then
    If IsDate(ActiveCell.Value) Then
    Tb_Test_Starting_Day.Text = CStr(ActiveCell.Value)
    Else
    MsgBox ("This cell has no date data, please select other cell")
    End If
    Else
    'do something else
    MsgBox "You haven't changed cells"
    End If

    Sheets(Sheet_Name).Activate
    End Sub
    [/VBA]
    Problem I have now is that in the userform once I press the button Cmd_Overview I will jump into the sheet PB4A_2010 and I got the message "You haven't changed cells", I would like that when I press the button it will wait until I select another cell apart from A1 and only after that proceed with the rest of the checks.

    Is this possible?

    Many thanks for your help
    Joao

  4. #4
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    How about supplying a workbook or at least all your code?

    P.S please use code tags by either highlighting all your code and then clicking the VBA button or click the button first then paste your code between the tags.
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  5. #5
    Hi,

    This is all my code:

    [VBA]
    Private Sub Test_New()
    Frm_Test_Manager.Show
    End Sub

    Sub Macro1()
    Test_New
    End Sub

    Private ub Cmd_Overview_Click()
    Dim Sheet_Name As String
    Dim MyCell As String

    Sheet_Name = ActiveSheet.Name
    Sheets("PB4A_2010").Activate
    ThisWorkbook.Sheets("PB4A_2010").Range("A1").Select

    MyCell = ActiveCell.Address
    If ActiveCell.Address <> MyCell Then
    If IsDate(ActiveCell.Value) Then
    Tb_Test_Starting_Day.Text = CStr(ActiveCell.Value)
    Else
    MsgBox ("This cell has no date data, please select other cell")
    End If
    Else
    'do something else
    MsgBox "You haven't changed cells"
    End If

    Sheets(Sheet_Name).Activate
    End Sub
    [/VBA]

  6. #6
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Please, in future use code tags as i indictated above!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  7. #7
    Hi,

    Sorry about that, I forgot to do that, it will not happen again ;-)

Posting Permissions

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