+ Reply to Thread
Results 1 to 7 of 7

Line of code works on one tab but not on others

  1. #1
    Registered User
    Join Date
    06-25-2018
    Location
    US
    MS-Off Ver
    2016
    Posts
    13

    Line of code works on one tab but not on others

    I have a work book with 4 tabs - Raw Data, Install, Early Failure and Reliability. I'm very new with macros, but with the help of the interwebs I was able to put together a macro which did what I wanted....at least on the first tab. Specifically, I needed it to pull out the specific category of data and put it in its respective tab. I created a command button to use. It worked perfectly on the Install tab, but I got an error when I tried it on the other tab. The only thing that changed in the code from tab to tab is the name of the worksheet (Install v. Early Failure v. Reliability). Everything else is exactly the same.

    Here is the code:

    Private Sub CommandButton1_Click()

    Application.ScreenUpdating = False

    a = Worksheets("Raw Data").Cells(Rows.Count, 1).End(xlUp).Row

    For i = 2 To a

    If Worksheets("Raw Data").Cells(i, 19).Value = "Repair" And Worksheets("Raw Data").Cells(i, 42).Value = "YES" Then

    Worksheets("Raw Data").Rows(i).Copy
    Worksheets("Early Failure").Activate
    b = Worksheets("Early Failure").Cells(Rows.Count, 1).End(xlUp).Row
    Worksheets("Early Failure").Cells(b + 1, 1).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Worksheets("Raw Data").Activate

    End If
    Next

    Application.CutCopyMode = False

    ThisWorkbook.Worksheets("Raw Data").Cells(1, 1).Select

    Application.ScreenUpdating = True

    End Sub

    When I clicked the Command Button on both the Early Failure and Reliability tabs I got this:

    Capture.PNG

    When I click to Debug it highlights the line in blue above. It does this for both the Early Failure and Reliability tabs.

    I've already tried a couple things:

    - Removing the line
    - Removing the line and removing the "Worksheets("Raw Data").Activate" line
    - Separating it into two lines:
    ThisWorkbook.Worksheets("Raw Data").Select
    Cells(1, 1).Select
    - Separating it into two lines and changing the second line:
    ThisWorkbook.Worksheets("Raw Data").Select
    Range("A1").Select

    None of these worked, and once I tried the last two, exited Design Mode and tried clicking the Command Buttons on each sheet...nothing happened. The macro didn't run and I didn't get an error.

    Any help would be really appreciated! Like I said, I'm very new to macros, so I'm sure it's something super simple.

    Thanks!!!!

    Amy

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Line of code works on one tab but not on others

    Amy,
    Use code tags with your code as per forum's rule.

    You do need a loop function. Filter is much faster.

    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Line of code works on one tab but not on others

    Further simplification.


    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    06-25-2018
    Location
    US
    MS-Off Ver
    2016
    Posts
    13

    Re: Line of code works on one tab but not on others

    Quote Originally Posted by AB33 View Post
    Amy,
    Use code tags with your code as per forum's rule.
    [/CODE]
    I don't know what that means. Sorry.

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Line of code works on one tab but not on others

    Look at my code. You need to wrap your code with code tags.

    Select:
    Select the entire text
    Click the pound(Hash) sign

  6. #6
    Valued Forum Contributor
    Join Date
    09-30-2018
    Location
    Vlaams Brabant Belgium
    MS-Off Ver
    365
    Posts
    456

    Re: Line of code works on one tab but not on others

    Hi amycat81178,

    When you post code click on the # in the bar above your text it will put the necessary tags for you and you can past in between them.

    Grtz

  7. #7
    Registered User
    Join Date
    06-25-2018
    Location
    US
    MS-Off Ver
    2016
    Posts
    13

    Re: Line of code works on one tab but not on others

    Ahhhh....I see. Thank you!!!

+ 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: 1
    Last Post: 07-02-2018, 07:32 PM
  2. [SOLVED] Error 1004 in certain line - The code works until line 152
    By REspina in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-01-2017, 11:08 AM
  3. how can i make this code works for multiple links it only works for one link
    By baig123 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-12-2014, 08:38 AM
  4. [SOLVED] Excel Border Line style works for the first time I run the code, later it shows some error
    By vidyaduttk in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-14-2014, 05:41 AM
  5. 8 Line Code Works On Other Computer, Not Mine
    By Relmiw in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-11-2014, 09:45 PM
  6. [SOLVED] Need help understanding why this line of code works.
    By jbwitty in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 09-26-2013, 01:01 AM
  7. combining sheets (code works from ron debruin but need 1 line modification)
    By Piyush in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-04-2005, 12:38 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