+ Reply to Thread
Results 1 to 3 of 3

Want to use Macro on any worksheet

  1. #1
    Registered User
    Join Date
    06-21-2021
    Location
    London
    MS-Off Ver
    10
    Posts
    2

    Want to use Macro on any worksheet

    Hi guys,

    please tell me someone can help. I've run this Macro and I want to be able to use it on any sheet - not just Sheet5 and Sheet 6.

    Could anyone please help?

    Thank you!!!

    PHP Code: 
    Sheets.Add After:=ActiveSheet
        Sheets
    ("2a. Fixed - Cost Forecast").Select
        Cells
    .Select
        Selection
    .Copy
        Sheets
    ("Sheet5").Select
        ActiveSheet
    .Paste
        Rows
    ("4:4").Select
        Range
    ("D4").Activate
        Application
    .CutCopyMode False
        Selection
    .AutoFilter
        Columns
    ("E:AG").Select
        Selection
    .Delete Shift:=xlToLeft
        Rows
    ("1:3").Select
        Range
    ("A3").Activate
        Selection
    .Delete Shift:=xlUp
        Cells
    .Select
        Selection
    .AutoFilter
        Selection
    .AutoFilter
        ActiveSheet
    .Range("$A$1:$BT$157").AutoFilter Field:=4Criteria1:="="
        
    Rows("5:5").Select
        Range
    (SelectionSelection.End(xlDown)).Select
        Selection
    .Delete Shift:=xlUp
        Rows
    ("1:1").Select
        Selection
    .AutoFilter
        Columns
    ("A:A").Select
        Selection
    .Delete Shift:=xlToLeft
        Range
    ("AB1").Select
        ActiveCell
    .FormulaR1C1 "Total"
        
    Range("B1").Select
        ActiveCell
    .FormulaR1C1 "Partner"
        
    Range("A1").Select
        Range
    (SelectionSelection.End(xlToRight)).Select
        Range
    (SelectionSelection.End(xlDown)).Select
        Range
    (SelectionSelection.End(xlDown)).Select
        Range
    (SelectionSelection.End(xlDown)).Select
        Range
    (SelectionSelection.End(xlDown)).Select
        Range
    (SelectionSelection.End(xlDown)).Select
        Range
    (SelectionSelection.End(xlDown)).Select
        Range
    (SelectionSelection.End(xlDown)).Select
        Range
    (SelectionSelection.End(xlDown)).Select
        Range
    (SelectionSelection.End(xlDown)).Select
        Range
    (SelectionSelection.End(xlDown)).Select
        Range
    (SelectionSelection.End(xlDown)).Select
        Range
    (SelectionSelection.End(xlDown)).Select
        Range
    (SelectionSelection.End(xlDown)).Select
        Range
    (SelectionSelection.End(xlDown)).Select
        Range
    (SelectionSelection.End(xlDown)).Select
        Range
    (SelectionSelection.End(xlDown)).Select
        Range
    (SelectionSelection.End(xlDown)).Select
        Range
    (SelectionSelection.End(xlDown)).Select
        Range
    (SelectionSelection.End(xlDown)).Select
        Range
    (SelectionSelection.End(xlDown)).Select
        Range
    (SelectionSelection.End(xlDown)).Select
        Range
    (SelectionSelection.End(xlDown)).Select
        Range
    (SelectionSelection.End(xlDown)).Select
        Range
    ("A1:AB1048575").Select
        Range
    (SelectionSelection.End(xlUp)).Select
        Sheets
    .Add
        ActiveWorkbook
    .PivotCaches.Create(SourceType:=xlDatabaseSourceData:= _
            
    "Sheet5!R1C1:R129C28"Version:=xlPivotTableVersion15).CreatePivotTable _
            TableDestination
    :="Sheet6!R3C1"TableName:="PivotTable8"DefaultVersion _
            
    :=xlPivotTableVersion15
        Sheets
    ("Sheet6").Select
        Cells
    (31).Select
        With ActiveSheet
    .PivotTables("PivotTable8").PivotFields("Partner")
            .
    Orientation xlRowField
            
    .Position 1
        End With
    End Sub 
    Last edited by ceiran1990; 06-21-2021 at 05:02 AM.

  2. #2
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: Want to use Macro on any worksheet

    please see forum rules - place your code between code tags as required.
    when this is done we will then be able to help you.
    torachan.

  3. #3
    Registered User
    Join Date
    06-21-2021
    Location
    London
    MS-Off Ver
    10
    Posts
    2

    Re: Want to use Macro on any worksheet

    Thanks. Should be done now.
    Last edited by ceiran1990; 06-21-2021 at 05:03 AM.

+ 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. Macro to copy data from multiple worksheet cells in to a single Master worksheet
    By thunt13 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-08-2015, 03:24 PM
  2. Replies: 3
    Last Post: 05-26-2014, 02:21 AM
  3. [SOLVED] Macro to Copy Master Worksheet create and paste in new auto named worksheet
    By TheRealLethality in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-15-2014, 12:46 AM
  4. [SOLVED] Macro/VBA code to Copy data from primary worksheet to a worksheet opened by macro
    By MHamid in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-30-2013, 11:10 AM
  5. Macro to select worksheet based on cell value and then return data to diff worksheet
    By clnossok in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-22-2013, 07:48 PM
  6. Excel 2010 Macro to copy worksheet, update formula and rename worksheet
    By madmak0203 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-29-2012, 09:18 PM
  7. Replies: 1
    Last Post: 08-29-2012, 07:11 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