+ Reply to Thread
Results 1 to 4 of 4

Code to select cell to the right of current cell.

Hybrid View

  1. #1
    Registered User
    Join Date
    03-06-2012
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2010
    Posts
    48

    Code to select cell to the right of current cell.

    So I use a macro to add column, selects column to the left of it, B in this case, move down till end, insert a 1 in the new column (at the bottom) which I later use to copy a new formula down

      Columns("C:C").Select
        Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
        Range("B1").Select
        Selection.End(xlDown).Select
        Range("C2236").Select
        ActiveCell.FormulaR1C1 = "1"
        Selection.End(xlUp).Select
        Range("C2").Select
        ActiveCell.FormulaR1C1 = "=IF(RC[-2]="""",RC[1],RC[-2]&"" GROUP"")"
        Range("C2").Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.FillDown
    The Column should always be the same, but I can't garentee the rows will be, so I'm wondering if I can tell the macro to selection end down and go right 1 rather than the specific cell C2236 which codes in when I use the right arrow.

    Thanks in advance for any help.
    Last edited by CDNcameron; 08-20-2013 at 02:42 PM.

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Code to select cell to the right of current cell.

    CDNcameron,

    Give this a try:
    Sub tgr()
        
        Columns("C").Insert
        With Range("C2:C" & Cells(Rows.Count, "B").End(xlUp).Row)
            .Formula = "=IF(A" & .Row & "="""",B" & .Row & ",A" & .Row & "&"" GROUP"")"
        End With
        
    End Sub
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Registered User
    Join Date
    03-06-2012
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2010
    Posts
    48

    Re: Code to select cell to the right of current cell.

    Thanks, but had just found

    activecell.offset(0,1).select
    which seems to be doing the job.

  4. #4
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Code to select cell to the right of current cell.

    Using select statements and activecell is bad practice. I would recommend learning how to avoid their use.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Select Named Range in current cell row
    By Jmeyering in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-22-2011, 05:25 PM
  2. current cell - select 5 to the right
    By RxMiller in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-14-2010, 02:44 PM
  3. VBA Select Previous Cell + Current
    By tpowell55 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-30-2010, 01:05 PM
  4. Assign current cell to a variable and re-select
    By Cumberland in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-29-2006, 10:47 PM
  5. Want macro to select current cell
    By rdaugherty in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-13-2005, 12:05 PM

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