+ Reply to Thread
Results 1 to 25 of 25

URGENT: Macro That Worked Fine Not Working Now - No Changes Made To Code

  1. #1
    Registered User
    Join Date
    05-14-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    17

    URGENT: Macro That Worked Fine Not Working Now - No Changes Made To Code

    Hi All,

    I am having a crisis as I can't figure out what is wrong with a macro I had written earlier, which was working flawlessly until recently.

    My excel workbook contains 3 sheets and The following are some of the issues I observed while running through the code in break mode.

    1. Copying values from one sheet to a specific cell in a specific sheet causes the value to be populated in the active sheet. Here's what the code looks like:

    Assume I am on Sheet 2 Then:

    Thisworkbook.Sheets("Sheet1").Activate
    Range("A1").Value = "Test"

    In this scenario, the value should have ideally been populated in Sheet 1 cell A1, but the value gets populated in Sheet 2 Cell A1....how is this possible? and why is this happening?

    2. A simple range statement results in a 10004 Error. Ex: Range("A1").select To overcome this I have to specifically mention which sheet i am referring to i.e. If the active sheeet is Sheet1 I am assuming the above line should work fine, but I have to modify it to Sheets("Sheet1").Range("A1").Select .... Why?

    I created a Test Workbook and the issue seems to be following in the workbook as well. The code is in the Sheet area of the workbook. In my actual file Im using a Button. Hope this adds more clarity. I've attached the Test workbook as well.

    I am completely baffled, I am not sure if a setting has changed or if there is an issue with Excel or my computer. I am not sure if anyone has come across this issue, but I would really appreciate all the help I can get.

    Thanks,
    Steve
    Attached Files Attached Files
    Last edited by stevevb; 05-15-2013 at 12:05 AM.

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: URGENT: Macro That Worked Fine Not Working Now - No Changes Made To Code

    Just a guess....

    Isn't the code written in Sheet2 module?

    Noticed you have attached the file.

    As I said, if the code is in written Sheet module, every Cells/Range object without its parent object is specified refers to the sheet that the code is written.
    Last edited by jindon; 05-15-2013 at 12:11 AM.

  3. #3
    Registered User
    Join Date
    05-14-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: URGENT: Macro That Worked Fine Not Working Now - No Changes Made To Code

    Hi jindon,

    I have used this before and it worked fine... infact i've been writing similar code using buttons and sheets for the past 1 year and this is the first time I've come across this problem. I wrote the test code in the area for Sheet1 to simulate my problem.

    Its funny how I designed this code on this very computer, implemented it at work, worked fine and now it doesn't work here anymore. I was and still am quite baffled.

    Will have to test this at work and see if the issue follows. When u ran the code are u facing the same issue?

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: URGENT: Macro That Worked Fine Not Working Now - No Changes Made To Code

    Quote Originally Posted by stevevb View Post
    Hi jindon,

    I have used this before and it worked fine...
    I can hardly believe that.

  5. #5
    Registered User
    Join Date
    05-14-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: URGENT: Macro That Worked Fine Not Working Now - No Changes Made To Code

    Thats exactly how I feel hence the shock and the need to post on a forum i wish I cld share screens with you to prove my point

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: URGENT: Macro That Worked Fine Not Working Now - No Changes Made To Code

    If that is the case, your Excel is now working properly.

    I don't know if you need to Activate Sheet2 intentionaly...

    This line should give you what you are trying to do.
    It is always better to qualify the parent object,
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    05-14-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: URGENT: Macro That Worked Fine Not Working Now - No Changes Made To Code

    Haha,

    I remember seeing the solution and figured the way to workaround the problem, but it still doesnt explain how the workbook i designed at home works fine on a different computer at work?

    Like I said, If i cld share screens with you, I cld prove my point.

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: URGENT: Macro That Worked Fine Not Working Now - No Changes Made To Code

    OK

    When you write a code in a Sheet module, Cells/Range/Shapes etc refers to its parent object that is the Sheet you write the code in.

    Range/Cells in Sheet module is referring not to ActiveSheet.Cells/Range, it is Me.Cell/Range, so it have to be impossible to refer to the cells/range in other sheet without qualifying the sheet object.

  9. #9
    Registered User
    Join Date
    05-14-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: URGENT: Macro That Worked Fine Not Working Now - No Changes Made To Code

    Hi Jindon,

    I've just tested the old code and it works despite not following the changes you suggested. I wish I cld show this to you.

    However, here's what I just observed. If I click on the button on the main sheet the code works flawlessly but If i go to VBeditor and run it in break mode it errors out on the Range("A2").select with the error 1004

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: URGENT: Macro That Worked Fine Not Working Now - No Changes Made To Code

    Can you just upload the file you are talking about?

  11. #11
    Registered User
    Join Date
    05-14-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: URGENT: Macro That Worked Fine Not Working Now - No Changes Made To Code

    This is the strange part. It is working!! but why? why do our opinions differ? and if u are right then my code should not execute.

    What is even stranger is the fact that it is working and not causing the same errors as I reported earlier. Baffled to the power infinity.

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: URGENT: Macro That Worked Fine Not Working Now - No Changes Made To Code

    Because I can not replicate the issue here and I don't think it is possible.

  13. #13
    Registered User
    Join Date
    05-14-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: URGENT: Macro That Worked Fine Not Working Now - No Changes Made To Code

    Im afraid I can't upload the actual workbook, it contains sensitive information and I'd have to take that out before I can send it to you.

    But the simulation was there in my test file... Like i said the code was written in Sheet1 module, The activesheet before macro execution was Sheet2. The code is
    ThisWorkbook.Sheets("Sheet2").Activate
    Range("A1").Value = "Test"

    The value should ideally come to sheet 2 cell A1 (according to me) but the old code is working even though i have not changed it as you suggested. But there are sporadic discrepancies.

  14. #14
    Registered User
    Join Date
    05-14-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: URGENT: Macro That Worked Fine Not Working Now - No Changes Made To Code

    Hi Jindon,

    Here's what I will do... You have been really helpful to reply so quick and look into this issue. I have to head to work now, so what I will do is...once I get back home, I will remove the sensitive info and send you the workbook. I hope that is fine?

  15. #15
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: URGENT: Macro That Worked Fine Not Working Now - No Changes Made To Code

    No problem.

  16. #16
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: URGENT: Macro That Worked Fine Not Working Now - No Changes Made To Code

    I wonder if there's any MISSING REFs in the Visual Basic Editor due to conflicting versions of Excel that the file is being used within?
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  17. #17
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: URGENT: Macro That Worked Fine Not Working Now - No Changes Made To Code

    You should be nominated for sainthood Jindon.

    I don't understand why it matters how it worked in the past? It was done incorrectly from the get-go and Jindon offered several solutions to fix the problem correctly. Putting this code in the worksheet's code module was\is\will be just bad practice and unnecessary regardless if it once worked.

  18. #18
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: URGENT: Macro That Worked Fine Not Working Now - No Changes Made To Code

    Quote Originally Posted by AlphaFrog View Post
    You should be nominated for sainthood Jindon.

    I don't understand why it matters how it worked in the past? It was done incorrectly from the get-go and Jindon offered several solutions to fix the problem correctly. Putting this code in the worksheet's code module was\is\will be just bad practice and unnecessary regardless if it once worked.
    Yeah, this guy should have realized his Excel is collapsed if he is saying truth.

  19. #19
    Registered User
    Join Date
    05-14-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: URGENT: Macro That Worked Fine Not Working Now - No Changes Made To Code

    Hi All,

    I just happened to see your comments Of course I admit programming in excel isnt my forte, somethings happen to be so simple in VB.Net. Also, I did check if there were any references I missed. Prior to Jindon's suggestions I already figured out how to make the code work, but what puzzled me was why did the previous code in the sheet module work fine? Also, why did the same thing work on a different machine? Isnt it assumption that my excel is messed up when I haven't changed anything?

    I've at the moment transferred the whole code to a module and I am using the button click event to run the sub which seems to have overcome all the problems. but

  20. #20
    Registered User
    Join Date
    05-14-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: URGENT: Macro That Worked Fine Not Working Now - No Changes Made To Code

    Alphafrog,

    It matters why it worked in the past cos thats when you know if something is wrong. If it were all perfect I wouldnt be posting here now would i?
    Also, if the parent object has to be referred etc VBA shouldn't have allowed the program to work in the first place.

    I've faced similar issues with different things in excel and always have been able to find a workaround, but it has left me puzzled so rather than being naive and ignorant about the subject, i felt it would be nice to take the advice of experts such as all of you
    Last edited by stevevb; 05-18-2013 at 09:40 AM.

  21. #21
    Registered User
    Join Date
    05-14-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: URGENT: Macro That Worked Fine Not Working Now - No Changes Made To Code

    Hi All,

    Here's another example where excel has failed to make me understand what I did wrong. The logic seems correct and I've used a similar logic in VB.NET. See the below code.

    On Error GoTo a:
    adoRS.Open Source:=strSQL, _
    ActiveConnection:=adocon, _
    CursorType:=adOpenKeyset, _
    LockType:=adLockOptimistic
    'On Error GoTo 0
    adoRS.Update

    ActiveCell.Offset(1, 0).Activate
    a: MsgBox ("Error")

    The problem is after one iteration the on error statement does not go to label 'a' i.e. it works the first time, but not the second. Forgot to mention that this is just part of a code and this is enclosed within a Do while .. Loop

  22. #22
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: URGENT: Macro That Worked Fine Not Working Now - No Changes Made To Code

    Quote Originally Posted by stevevb View Post
    Prior to Jindon's suggestions I already figured out how to make the code work, but what puzzled me was why did the previous code in the sheet module work fine?
    So this wan't URGENT and you were not having a crisis?

    The thread reads as if you were rejecting Jindon's correct suggestions to fix the problem and was only interested in making an already flawed application work again. That's why I nominated him for sainthood.

    You never indicated that you had a working solution and was now just interested in understanding what changed. It reads as if you just ignored all of jindon's good advice.

  23. #23
    Registered User
    Join Date
    05-14-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: URGENT: Macro That Worked Fine Not Working Now - No Changes Made To Code

    Hi AlphaFrog,

    The issue was urgent because it was supposed to be run the same day I posted the thread, at work. I was just testing the application one last time and that's when all of the errors started coming up. I obviously panicked but as you can see from one of threads I did tell Jindon that I'd send the code after removing the details which I couldn't owing to my schedule and more work getting piled on. Once I was at work as I could not access these forums owing to the company's policies and I had no choice but to re-do the code in a module and calling it in the button click event which resolved the issue.

    When I posted that reply to know why it worked earlier, the urgency was over. I also ended up reading on the subject and I agree to Jindon that what I was doing was wrong. So yes apologies if it felt like I was rejecting advice.

    When I post on these forums I do not sit idle, cos I know that someone may reply but I don't know when. So I read,research and try to figure out things by trial and error.

    Hope that gives clarity on the events that transpired.

  24. #24
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: URGENT: Macro That Worked Fine Not Working Now - No Changes Made To Code

    URGENT in thread titles tends to put people's teeth on edge -- it suggests that your problem is more critical than others, which you have no way of knowing. My practice is to just not answer.
    Entia non sunt multiplicanda sine necessitate

  25. #25
    Registered User
    Join Date
    05-14-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: URGENT: Macro That Worked Fine Not Working Now - No Changes Made To Code

    I will bear that in mind next time. I apologize

+ 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