+ Reply to Thread
Results 1 to 3 of 3

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

    Hi, Unfortunately your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    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.

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,895

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

    Your post does not comply with Rule 8 of our Forum RULES. Do not crosspost your question on multiple forums without including links here to the other threads on other forums.

    Please take the time to read our forum rules. You have violated two rules on your first post, so I assume you have not read them.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).


    CrossPost: http://www.mrexcel.com/forum/excel-q...statement.html
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

+ 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. 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. [SOLVED] 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