Closed Thread
Results 1 to 2 of 2

Help with applying Macro to specific worksheets with unique identifiers

  1. #1
    Registered User
    Join Date
    09-12-2014
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel
    Posts
    5

    Help with applying Macro to specific worksheets with unique identifiers

    Hi everyone,

    I'm trying to write a macro to look at all of the worksheets in a workbook and apply a certain but similar code to the worksheets depending on the worksheet name. One thing to note is the worksheets name has a possibility of being different, but still will contain a unique identifier somewhere in the name, such as the name of the work sheet could be GL, xxxx GL xxxx, GL xxxx, or xxxx GL with the xxxx representing some other word. Right now my code does not perform anything. The names of the worksheets at the moment are GL PL, AL, and ER

    Here is my example code. The macro beneath the if statement works properly. I just need help using them to the right worksheets. Thanks

    Application.Workbooks.Open (Analysis.Path & "\" & datarec & ".xlsm")
    Set datarec2 = ThisWorkbook
    Dim ws As Worksheet
    For Each ws In datarec2.Worksheets


    If ws.Name Like "* GL *" Or ws.Name Like "GL" Then

    Range("N115").Select
    Selection.End(xlDown).Select
    ActiveCell.Offset(1, 0).Select
    Range(ActiveCell.Offset(0, -13), ActiveCell.Offset(50, -13)).Copy
    Analysis.Sheets("Large Losses - GL").Range("c9").PasteSpecial xlPasteValues
    Range(ActiveCell.Offset(0, -12), ActiveCell.Offset(50, -12)).Copy
    Analysis.Sheets("Large Losses - GL").Range("d9").PasteSpecial xlPasteValues
    Range(ActiveCell.Offset(0, -11), ActiveCell.Offset(50, -11)).Copy
    Analysis.Sheets("Large Losses - GL").Range("o9").PasteSpecial xlPasteValues
    Range(ActiveCell.Offset(0, -10), ActiveCell.Offset(50, -10)).Copy
    Analysis.Sheets("Large Losses - GL").Range("a9").PasteSpecial xlPasteValues
    Range(ActiveCell.Offset(0, -9), ActiveCell.Offset(50, -9)).Copy
    Analysis.Sheets("Large Losses - GL").Range("e9").PasteSpecial xlPasteValues
    Range(ActiveCell.Offset(0, -7), ActiveCell.Offset(50, -7)).Copy
    Analysis.Sheets("Large Losses - GL").Range("p9").PasteSpecial xlPasteValues
    Range(ActiveCell.Offset(0, 2), ActiveCell.Offset(50, 2)).Copy
    Analysis.Sheets("Large Losses - GL").Range("f9").PasteSpecial xlPasteValues
    Range(ActiveCell.Offset(0, 3), ActiveCell.Offset(50, 3)).Copy
    Analysis.Sheets("Large Losses - GL").Range("g9").PasteSpecial xlPasteValues
    Range(ActiveCell.Offset(0, 6), ActiveCell.Offset(50, 6)).Copy
    Analysis.Sheets("Large Losses - GL").Range("h9").PasteSpecial xlPasteValues
    Range(ActiveCell.Offset(0, 5), ActiveCell.Offset(50, 5)).Copy
    Analysis.Sheets("Large Losses - GL").Range("j9").PasteSpecial xlPasteValues
    End If


    If ws.Name Like ("* AL *") Or ws.Name Like "AL" Then


    Range("N115").Select
    Selection.End(xlDown).Select
    ActiveCell.Offset(1, 0).Select
    Range(ActiveCell.Offset(0, -13), ActiveCell.Offset(50, -13)).Copy
    Analysis.Sheets("Large Losses - AL").Range("c9").PasteSpecial xlPasteValues
    Range(ActiveCell.Offset(0, -12), ActiveCell.Offset(50, -12)).Copy
    Analysis.Sheets("Large Losses - AL").Range("d9").PasteSpecial xlPasteValues
    Range(ActiveCell.Offset(0, -11), ActiveCell.Offset(50, -11)).Copy
    Analysis.Sheets("Large Losses - AL").Range("o9").PasteSpecial xlPasteValues
    Range(ActiveCell.Offset(0, -10), ActiveCell.Offset(50, -10)).Copy
    Analysis.Sheets("Large Losses - AL").Range("a9").PasteSpecial xlPasteValues
    Range(ActiveCell.Offset(0, -9), ActiveCell.Offset(50, -9)).Copy
    Analysis.Sheets("Large Losses - AL").Range("e9").PasteSpecial xlPasteValues
    Range(ActiveCell.Offset(0, -7), ActiveCell.Offset(50, -7)).Copy
    Analysis.Sheets("Large Losses - AL").Range("p9").PasteSpecial xlPasteValues
    Range(ActiveCell.Offset(0, 2), ActiveCell.Offset(50, 2)).Copy
    Analysis.Sheets("Large Losses - AL").Range("f9").PasteSpecial xlPasteValues
    Range(ActiveCell.Offset(0, 3), ActiveCell.Offset(50, 3)).Copy
    Analysis.Sheets("Large Losses - AL").Range("g9").PasteSpecial xlPasteValues
    Range(ActiveCell.Offset(0, 6), ActiveCell.Offset(50, 6)).Copy
    Analysis.Sheets("Large Losses - AL").Range("h9").PasteSpecial xlPasteValues
    Range(ActiveCell.Offset(0, 5), ActiveCell.Offset(50, 5)).Copy
    Analysis.Sheets("Large Losses - AL").Range("j9").PasteSpecial xlPasteValues
    End If


    If ws.Name Like "* EL *" Or ws.Name Like "EL" Or ws.Name Like "* WC *" Or ws.Name Like "WC" Or ws.Name Like "* ER *" Or ws.Name = "ER" Then


    Range("N115").Select
    Selection.End(xlDown).Select
    ActiveCell.Offset(1, 0).Select
    Range(ActiveCell.Offset(0, -13), ActiveCell.Offset(50, -13)).Copy
    Analysis.Sheets("Large Losses - WC").Range("c9").PasteSpecial xlPasteValues
    Range(ActiveCell.Offset(0, -12), ActiveCell.Offset(50, -12)).Copy
    Analysis.Sheets("Large Losses - WC").Range("d9").PasteSpecial xlPasteValues
    Range(ActiveCell.Offset(0, -11), ActiveCell.Offset(50, -11)).Copy
    Analysis.Sheets("Large Losses - WC").Range("o9").PasteSpecial xlPasteValues
    Range(ActiveCell.Offset(0, -10), ActiveCell.Offset(50, -10)).Copy
    Analysis.Sheets("Large Losses - WC").Range("a9").PasteSpecial xlPasteValues
    Range(ActiveCell.Offset(0, -9), ActiveCell.Offset(50, -9)).Copy
    Analysis.Sheets("Large Losses - WC").Range("e9").PasteSpecial xlPasteValues
    Range(ActiveCell.Offset(0, -7), ActiveCell.Offset(50, -7)).Copy
    Analysis.Sheets("Large Losses - WC").Range("p9").PasteSpecial xlPasteValues
    Range(ActiveCell.Offset(0, 2), ActiveCell.Offset(50, 2)).Copy
    Analysis.Sheets("Large Losses - WC").Range("f9").PasteSpecial xlPasteValues
    Range(ActiveCell.Offset(0, 3), ActiveCell.Offset(50, 3)).Copy
    Analysis.Sheets("Large Losses - WC").Range("g9").PasteSpecial xlPasteValues
    Range(ActiveCell.Offset(0, 6), ActiveCell.Offset(50, 6)).Copy
    Analysis.Sheets("Large Losses - WC").Range("h9").PasteSpecial xlPasteValues
    Range(ActiveCell.Offset(0, 5), ActiveCell.Offset(50, 5)).Copy
    Analysis.Sheets("Large Losses - WC").Range("j9").PasteSpecial xlPasteValues
    End If
    Next ws

    End Sub

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Help with applying Macro to specific worksheets with unique identifiers

    Welcome to the Forum, unfortunately:

    This is a duplicate post and as such does not comply with Rule 5 of our forum rules. This thread will now be closed, you may continue in your other thread.

    Thread Closed.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 7
    Last Post: 06-27-2014, 02:26 AM
  2. Sorting based on unique identifiers
    By excel_beginner2 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-04-2014, 10:09 AM
  3. How to merge different spreadsheets with no unique identifiers
    By newbieexcelgirl in forum Excel General
    Replies: 2
    Last Post: 01-17-2013, 11:42 AM
  4. Need a formula or Macro to correspond to unique identifiers
    By mike12345 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-14-2011, 10:50 AM
  5. How do I match unique identifiers on two Excel worksheets?
    By Randi Hagen,--Flagler College in forum Excel General
    Replies: 1
    Last Post: 02-03-2006, 11:10 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