+ Reply to Thread
Results 1 to 14 of 14

Problem with same VB Code used on different file

  1. #1
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Problem with same VB Code used on different file

    Hello:

    Please refer to 2 attached excel file.

    Although both files are using same data and same VB Code, the macro works on Ed-Employee-Shift file and macro would give error
    if i use the same Macro in Test-Employee-Shift file.

    Can someone please help figure out what is the problem and resolve this problem for me.

    Please let me KNOW IF ANY QUESTIONS.

    Thanks

    Riz
    Attached Files Attached Files
    Last edited by rizmomin; 05-07-2013 at 08:48 AM.

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

    Re: Problem with same VB Code used on different file

    The code shows an error on this line
    Please Login or Register  to view this content.

  3. #3
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Problem with same VB Code used on different file

    Hi AB33:

    Yes i know but what do you think the problem is.
    I am using the same data and same code?

    Please help

    Thanks

    Riz

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

    Re: Problem with same VB Code used on different file

    Riz,
    Please remove the code from sheets and put it in to to module. I have got the same error, on the same line.

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

    Re: Problem with same VB Code used on different file

    You need to put the range, or cells reference in to this line

    Please Login or Register  to view this content.

  6. #6
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Problem with same VB Code used on different file

    Hi AB33:

    I have done that also and still same problem.

    Have a look at attached excel file.

    Thanks a lot for help

    Riz
    Attached Files Attached Files

  7. #7
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Problem with same VB Code used on different file

    Hi AB33:

    The value of Cells(Row,Column) is flowing from code line 5 and 7.
    Please have a look at the top lines of the code.

    Thanks

    Riz

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

    Re: Problem with same VB Code used on different file

    Riz,
    The error is obvious
    Please Login or Register  to view this content.
    The row and column defined in the code are specifically( Private Sub CommandButton1_Click() )applied to that code only.
    When the code jumps in to next code "Sub Clear_Cells()", it does not know the row and column numbers. If I change the row and column in to this
    Please Login or Register  to view this content.
    The code works

  9. #9
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Problem with same VB Code used on different file

    Hi AB33:

    I am not good in understanding the VB Code.
    Someone on the forum had helped me with the code.
    Can you help me use the same code and make this code so that the code can be applied to any file.

    I would really appreciate your help.

    Thanks

    Riz

  10. #10
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Problem with same VB Code used on different file

    Hi AB33:

    I would appreciate if you open the File : Ed-Employee-Shift.xls as i have uploaded and run the macro so that you can understand what it does.
    And i want to use the same code in my own worksheet to ACCOMPLISH the result.

    please let me know if any questions

    Thanks

    Riz

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

    Re: Problem with same VB Code used on different file

    Riz,
    First,
    Does the amend code work, or not? Cells(3, 6).Select
    If this what you wanted, I can correct the code.

  12. #12
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Problem with same VB Code used on different file

    Hi AB33:

    When i change and amend the code to Cell(3,6).select, it goes and error at Sub_Color Cells : Cell(row,colum).select.
    Now changed this code to Cell(3,6).select and then it errors at Line#21 for code : If first_four_digits < 1400 And Last_four_digits < 1400 Then

    Does the whole code works for you?

    Let me KNOW IF ANY QUESTIONS.

    Thanks for your help.

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

    Re: Problem with same VB Code used on different file

    Does the whole code works for you? Not really!
    I have changed some of the lines, and I did not get an error, but the code has infinite loop, it will not stop and will go for ever.
    Perhaps, if you could explain to me what was the purpose of the code, or what you were trying to achieve, I can either amend the code, or write you a new one.

  14. #14
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Problem with same VB Code used on different file

    Hi AB33:

    Leith Ross helped and he rewrote the code and it works.
    Thanks a lot for your help.

    Riz

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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