+ Reply to Thread
Results 1 to 3 of 3

Running Macro on a Different Worksheet

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-18-2014
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2013
    Posts
    197

    Running Macro on a Different Worksheet

    I'm using VBA to find the row under LastRow and then clear the selection.

    Sub Macro2()
    Dim LastRow As Integer
        LastRow = Cells(Rows.Count, "A").End(xlUp).Row
        If LastRow = 0 Then LastRow = 1
        Rows(LastRow + 1).Select
        Selection.ClearContents
    End Sub

    The code works perfectly, but only on the current worksheet. Is it possible to do this on another worksheet without having to go to that worksheet and run another macro?

    In this case it would be 'Sheet1 (2)'


    Thanks!!

  2. #2
    Forum Contributor
    Join Date
    02-18-2014
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2013
    Posts
    197

    Re: Running Macro on a Different Worksheet

    Nevermind. I figured it out.

    Dim LastRow As Integer
        Sheets("Sheet1 (3)").Select
        LastRow = Cells(Rows.Count, "A").End(xlUp).Row
        If LastRow = 0 Then LastRow = 1
        Rows(LastRow + 1).Select
        Selection.ClearContents
    End Sub

  3. #3
    Registered User
    Join Date
    01-27-2015
    Location
    Queanbeyan, Australia
    MS-Off Ver
    2010
    Posts
    5

    Re: Running Macro on a Different Worksheet

    Try prefacing the code with the sheet in question

    Sub Macro2()
    Dim LastRow As Integer
        LastRow = Sheets("Sheet1 (2)").Cells(Sheets("Sheet1 (2)").Rows.Count, "A").End(xlUp).Row
        If LastRow = 0 Then LastRow = 1
        Sheets("Sheet1 (2)").Rows(LastRow + 1).ClearContents
    End Sub

+ 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. [SOLVED] How to prevent worksheet code from running while Module Macro is running:
    By Chad Bateman in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-11-2015, 09:26 AM
  2. Slow running worksheet macro
    By Phil Payne in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-26-2014, 03:59 PM
  3. Selecting Worksheet then running macro based on selected worksheet
    By CircuitAkita in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-18-2011, 01:00 AM
  4. running Macro on a Protected Worksheet
    By Martha in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-06-2008, 02:29 PM
  5. Running macro on the perticular worksheet only
    By vanessa h in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-25-2006, 06:41 AM

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