+ Reply to Thread
Results 1 to 8 of 8

How to activate a past activecell

Hybrid View

  1. #1
    Registered User
    Join Date
    12-22-2010
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    16

    How to activate a past activecell

    I am writing a macro which uses a loop to find a certain cell and then it copies the cell to the left and pastes it on another sheet, but when it goes to paste on another sheet a new cell is activated. I need the macro to keep looping on the initial sheet but now that cell (copied from) is not active anymore. How can i make it so the macro remembers that initial cell (on initial sheet) and continue the loop from there?
    Last edited by romperstomper; 01-28-2011 at 12:41 PM.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,972

    Re: How to activate a past activecell

    It would help to see the code. You almost never need to select or activate anything in code anyway.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Registered User
    Join Date
    12-22-2010
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: How to activate a past activecell

    I need the loop to continue searching from the first place the "IF" statement is satisfied.

    It would be something like this:

    Sheets("Testing").Activate
    
    Range("L2").Select
    
    Do
    
    If ActiveCell = "Z" Then
        ActiveCell.Offset(0, -8).Select
        Selection.Copy
        Sheets("TestingPasteSheet").Activate
        Range("A300").Select
        ActiveCell.End(xlUp).Offset(1, 0).Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
    End If
    
    ActiveCell.Offset(1, 0).Select
    
    Loop Until IsEmpty(ActiveCell.Offset(0, 2)) = True

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,972

    Re: How to activate a past activecell

    Try this:
    
    Dim n As Long
    n = 0
    With Sheets("Testing").Range("L2")
    
    Do
    
       If .Offset(n, 0).Value = "Z" Then
           Sheets("TestingPasteSheet").Range("A300").End(xlUp).Offset(1, 0).Value = .Offset(0, -8).Value
       End If
       n = n + 1
       
    Loop Until IsEmpty(.Offset(n, 2))

  5. #5
    Registered User
    Join Date
    12-22-2010
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: How to activate a past activecell

    not picking up the right cells for some reason, but that's a much nicer code! thanks!

    I'll try adjusting it so I can get it to pick up the right numbers (relating to "Z").

    edit: needed to change .Offset(0, -8).Value to .Offset(n, -8).Value, working perfectly now!!! thanks so much!
    Last edited by PunPryde; 01-28-2011 at 12:31 PM.

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,972

    Re: How to activate a past activecell

    Yep, well spotted. Sorry about that!

  7. #7
    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 activate a past activecell

    I think it needs a slight amendment

    Edit: Romper replied whilst I was looking at it
    
    Dim n As Long
    n = 0
    With Sheets("Testing").Range("L2")
    
    Do
       If .Offset(n, 0).Value = "Z" Then
           Sheets("TestingPasteSheet").Range("A300").End(xlUp).Offset(1, 0).Value = .Offset(n, -8).Value
       End If
       n = n + 1
    Loop Until IsEmpty(.Offset(n, 2))
    
    End With
    Hope that helps.

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

    Free DataBaseForm example

  8. #8
    Registered User
    Join Date
    12-22-2010
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: How to activate a past activecell

    Been trying to figure out this for hours... after I posted it was solved in 5 mins! Thanks guys, best excel forums ever, quick too!

+ 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