+ Reply to Thread
Results 1 to 4 of 4

How to select activecell

Hybrid View

  1. #1
    Registered User
    Join Date
    04-28-2010
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    26

    How to select activecell

    Hi,

    Plzzz help...I have the following code in worksheet_selectionchange.
    I believe the code-If ActiveCell.Address = "H"&i- does not work.
    In column F, I have drop down list with 'Yes' or 'No' as options.
    If the user chooses 'Yes' in column F, check if user has skipped column G and moved to column H in which case the mesg pops up saying column G cant be blank. If it is not blank, then do a few vlookups on the next few cells.
    What part of my code is faulty?


    For i=2 to 10
    If Range("K" & i) = "" Or Range("L" & i) = "" Then
    If Target.Row = i And Target.Column = 6 Then
    
    If Range("F" & i).Value = "Yes" Then
    If ActiveCell.Address = "H" & i
             If Range("G" & i) = "" Then
                MsgBox ("Column G cannot be blank if you choose 'yes'.")
                Range("F" & i).Select
                else
               blah blah
               end if
    else If Range("F" & i).Value = "No" Then
             blah blah
            end if
    end if
    else
    end if
    else 
    end if
    
    
    next i

  2. #2
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,375

    Re: How to select activecell

    Hello excel_vb,

    maybe you should take a look at what ActiveCell.Address returns. Hop into the Immediate Window and type

    debug.print ActiveCell.address

    Then study the result.

    You'll find that the cell address is returned as $A$1, i.e. with the $ sign.

    Thus, your code must include the $ sign as well. Like in this code snippet

    Sub what()
    Dim i As Integer
    i = 1
    
    If ActiveCell.Address = "$A$" & i Then
        MsgBox "This is the active cell"
    Else
        MsgBox "this is not the active cell"
    End If
    
    End Sub
    can you take it from here?
    Last edited by teylyn; 05-02-2010 at 12:51 AM.

  3. #3
    Registered User
    Join Date
    04-28-2010
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    26

    [SOLVED] How to select activecell

    yes, it did.
    Thanks Teylyn!

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: How to select activecell

    Presumably you are using a worksheet event, you should post the full code, then Target would be the ActiveCell so how can this ever be true
    If Target.Row = i And Target.Column = 6 Then
    'etc
    If ActiveCell.Address = "H" & i
    What are you actually trying to do?
    Last edited by royUK; 05-02-2010 at 03:20 AM.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ 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