+ Reply to Thread
Results 1 to 9 of 9

Can someone please help me debug this dictionary code? I can't seem to get this to work

  1. #1
    Registered User
    Join Date
    03-26-2014
    MS-Off Ver
    Excel 2013
    Posts
    31

    Can someone please help me debug this dictionary code? I can't seem to get this to work

    I essentially want to calculate the profit/loss for each stock in column L.

    I want to use dictionaries to accomplish this.

    Does anyone know what's wrong with my code?
    Thanks!

    Please Login or Register  to view this content.
    Crossposted on: http://www.mrexcel.com/forum/excel-q...it-stocks.html


    clerktestwithdictionary.xlsm
    Last edited by potterotter; 06-22-2014 at 10:04 AM.

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

    Re: Can someone please help me debug this dictionary code? I can't seem to get this to wor

    Because of these lines, the code will copy nothing.

    Please Login or Register  to view this content.
    I think you are calculating the values for each symbol by multiplying the price by the quantity. But I do not know how you got the value in column "Last Trade".
    Could you explain a bit what are you trying to achieve?

  3. #3
    Registered User
    Join Date
    03-26-2014
    MS-Off Ver
    Excel 2013
    Posts
    31

    Re: Can someone please help me debug this dictionary code? I can't seem to get this to wor

    Quote Originally Posted by AB33 View Post
    Because of these lines, the code will copy nothing.

    Please Login or Register  to view this content.
    I think you are calculating the values for each symbol by multiplying the price by the quantity. But I do not know how you got the value in column "Last Trade".
    Could you explain a bit what are you trying to achieve?
    Thanks for your reply!

    Essentially I was given data in column A,B,C, D, L and M.
    I calculated column N using another macro as a checker.

    I want to calculate the profit for the stocks in column L and place it in column O.
    Column M (Last trade) is the last traded price of those stocks. Column C (Price) is the price at which the stock was bought.

    Please let me know if this is unclear! Thanks!

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

    Re: Can someone please help me debug this dictionary code? I can't seem to get this to wor

    I do not know what is the relevance of Column B. I have only used column A, C, D and L to calculate the PL, which is P*Q.
    If this is not what you wanted, you need to explain in more details.
    Attached Files Attached Files
    Last edited by AB33; 06-21-2014 at 02:42 PM.

  5. #5
    Registered User
    Join Date
    03-26-2014
    MS-Off Ver
    Excel 2013
    Posts
    31

    Re: Can someone please help me debug this dictionary code? I can't seem to get this to wor

    Quote Originally Posted by AB33 View Post
    I do not know what is the relevance of Column B. I have only used column A, C, D and L to calculate the PL, which is P*Q.
    If this is not what you wanted, you need to explain in more details.
    Thanks for your reply!

    The significance of column B is whether you are Buying (B) or Selling Short (S) a stock. If you are buying a stock then if the last traded price (Column M) is higher than the price bought (Column C) then you would make a profit. Conversely, if you were selling short a stock and the last trade price (M) is HIGHER than the price bought (C) you would LOSE money.

    Thanks for writing a code. I would like to find out what is wrong with my existing code? I understand that the symbol = activesheet.cells(i,12) will not return anything but what can I do to rectify this? Or is my code completely wrong?

    Sorry I am new to VBA and dictionaries so any help I can get will be much appreciated!

    Thanks you so much!

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

    Re: Can someone please help me debug this dictionary code? I can't seem to get this to wor

    The reason for writing my own code is that I do not understand your question.
    Looking at your code, Column L (12) does not appear until the last lines, so where does it show you are comparing column against Column L?
    You are correctly loading the data in to items (grossconsideration), but you are not using these items further down the lines.
    The items plays important role if you are using dictionary.
    You might not need to use 3 dictionaries. One or 2 would be suffice.

  7. #7
    Registered User
    Join Date
    03-26-2014
    MS-Off Ver
    Excel 2013
    Posts
    31

    Re: Can someone please help me debug this dictionary code? I can't seem to get this to wor

    Thanks! You're right! I used the wrong dictionary in the last bit. I changed it to stockdic now but I tried and it doesn't work.

    Is it a syntax issue? I am not sure if I am properly storing and retrieving the items in the dictionary. Do I need to add a .value at the back?

    This is my new code (I changed the last bit at the bottom). Thanks so much for your patience - I'm still learning.

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    03-26-2014
    MS-Off Ver
    Excel 2013
    Posts
    31

    Re: Can someone please help me debug this dictionary code? I can't seem to get this to wor

    Thanks! You're right! I used the wrong dictionary in the last bit. I changed it to stockdic now but I tried and it doesn't work.

    Is it a syntax issue? I am not sure if I am properly storing and retrieving the items in the dictionary. Do I need to add a .value at the back?

    This is my new code (I changed the last bit at the bottom). Thanks so much for your patience - I'm still learning.

    Please Login or Register  to view this content.

  9. #9
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Can someone please help me debug this dictionary code? I can't seem to get this to wor

    Hi, potterotter,

    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.

    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).

    http://www.mrexcel.com/forum/excel-q...it-stocks.html

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  10. #10
    Registered User
    Join Date
    03-26-2014
    MS-Off Ver
    Excel 2013
    Posts
    31

    Re: Can someone please help me debug this dictionary code? I can't seem to get this to wor

    Thanks! I have edited the first post

+ 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. [SOLVED] Code using dictionary class is too slow- need it work faster if possible.
    By strud in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 02-04-2014, 12:09 PM
  2. VBA Code Runs in Debug Mode But Returns Type Mismatch Error Outside Debug Mode
    By valerie.k.chiang in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-24-2014, 03:48 PM
  3. [SOLVED] Debug: How to debug this code?
    By reach78 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 09-25-2013, 07:16 AM
  4. [SOLVED] Any reason this VB script would work for some, but debug as read-only for others?
    By jackalc in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-08-2013, 07:17 AM
  5. [SOLVED] how do I debug my Excel macro & make it actually WORK?
    By Brainless_in_Boston in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 02-16-2006, 04:35 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