+ Reply to Thread
Results 1 to 3 of 3

Macro below specific to a single Worksheet?

Hybrid View

  1. #1
    Registered User
    Join Date
    02-18-2015
    Location
    HOLLAND MI
    MS-Off Ver
    WINDOWS 7 PROFESSIONAL
    Posts
    61

    Macro below specific to a single Worksheet?

    Hello,

    How can I make the Macro below specific to a single Worksheet?


    Sub CopyTrend()
    
    Range("E3:F22").SORT Key1:=Range("F3"), Order1:=xlAscending, _
    Header:=xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
    
    Dim column_number As Long
    column_number = ActiveSheet.Cells.Find(What:="*", After:=Range("IV65536"), SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column + 1
    Range(Cells(3, column_number), Cells(22, column_number + 1)).Value = Range("E3:F22").Value
    
    End Sub
    Thanks!

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro below specific to a single Worksheet?

    You could add the appropriate sheet reference.

    For example to make it refer to Sheet1.
    Sub CopyTrend()
    Dim column_number As Long
    
        With Sheets("Sheet1")
            .Range("E3:F22").SORT Key1:=.Range("F3"), Order1:=xlAscending, _
                 Header:=xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
    
            column_number = .Cells.Find(What:="*", After:=.Range("IV65536"), SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column + 1
            .Range(.Cells(3, column_number), .Cells(22, column_number + 1)).Value = .Range("E3:F22").Value
        End With
    
    End Sub
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    02-18-2015
    Location
    HOLLAND MI
    MS-Off Ver
    WINDOWS 7 PROFESSIONAL
    Posts
    61

    Re: Macro below specific to a single Worksheet?

    Yep! As you can tell... newbie.

    Thanks Norie!

+ 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. Copying specific data to a specific field in a worksheet macro
    By bradpeh in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-31-2013, 01:52 AM
  2. Run several sheet specific VBA Codes from a single Macro
    By hangmattan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-29-2013, 06:42 AM
  3. Replies: 3
    Last Post: 06-17-2013, 06:00 AM
  4. Macro to copy tables from specific worksheets into a single worksheet.
    By roshanvmech in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 06-12-2013, 09:07 AM
  5. Macro to pull specific data from one worksheet to another worksheet
    By Kettie in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-17-2013, 05:21 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