+ Reply to Thread
Results 1 to 2 of 2

NooB question on macros

Hybrid View

  1. #1
    Registered User
    Join Date
    05-12-2006
    Posts
    10

    NooB question on macros

    I have a macro that runs each time the user changes cell, at the end of the macro I then want to be returned to the original cell and I can't figure out how to do this. My macro

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Application.EnableEvents = False
    .
    .
    .
    Range(Target).Select
    Application.EnableEvents = True
    End Sub

    This throws an error, so I am not sure how to do this. Any help appreciated.

    Thanks in advance.

  2. #2
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Good afternoon JHalsall

    Add this line before your macro does anything (this will "remember" the address of the active cell) :
    UsrCell = ActiveCell.Address
    Use this line when you want to select it again :
    Range(UsrCell).Select
    Also, be aware that in most instances you don't have to select cells to perform an action in them, for example, the recorded macro :
    Range("B1").Select
    ActiveCell.FormulaR1C1 = "hello"
    could be simplified thus :
    Range("B1").Value="hello"
    HTH

    DominicB
    Please familiarise yourself with the rules before posting. You can find them here.

+ 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