+ Reply to Thread
Results 1 to 10 of 10

How to DRAW a line in VBA

  1. #1
    Registered User
    Join Date
    03-07-2014
    Location
    Copenhagen
    MS-Off Ver
    Excel 2007
    Posts
    5

    How to DRAW a line in VBA

    Attachment 302856Hi everyone,

    Can somebody help me with my problem.
    I'm trying to make a timeline which moves depending on which week it is. So I define the week number in a cell, search for the the value of this week and get to the cell from where to start drawing a line by using that code:
    Please Login or Register  to view this content.
    From here I found a code that can Draw a line through the center of the cells:

    Please Login or Register  to view this content.
    My question is how to combine these macros so the line will be drawn depending on the week number. I mean so this line can change values:

    Please Login or Register  to view this content.
    And the second question, how to change color of the line to red? I've tried with this one but with no luck:
    '.ForeColor.RGB = RGB(255, 0, 0) ' red

    I've tried in different ways for 2 days now without luck.


    I hope somebody can help!

    Thanks in advance!

    Michael
    Attached Files Attached Files
    Last edited by malyshkin; 03-08-2014 at 07:30 AM. Reason: Code editing

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: How to DRAW a line in VBA

    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)


    Does the cell you search for contain "C1" or "C10". Or is the position of the cell to be used instead of either "C1" or "C10"?

    Does the line move or just get longer? Perhaps an example file would help explain your problem
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    03-07-2014
    Location
    Copenhagen
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: How to DRAW a line in VBA

    Hi Andy

    Thank you for your answer,

    I've now edited my post with code tags.

    For my problem, the Cells "C1" and "C10" is just an example, and yes, I want to define where to Draw a line depending on the week.

    I attach an example.

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: How to DRAW a line in VBA

    Thanks for fixing code tags.

    Did you attach example file?

  5. #5
    Registered User
    Join Date
    03-07-2014
    Location
    Copenhagen
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: How to DRAW a line in VBA

    Thank you,

    Yes, I did.

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: How to DRAW a line in VBA

    Okay so you need to explain, for you file, where should the line be drawn. Where does it start, where does it finish?

    You have a date in A1 but no other real dates.

  7. #7
    Registered User
    Join Date
    03-07-2014
    Location
    Copenhagen
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: How to DRAW a line in VBA

    I have just updated the attached file.

    So, the macro starts at A1, check the week number, finds the corresponding week number in the first row, offsets 7 cells Down (B8) and from there I want it to Draw the line through the middle of the cells to B60.

    I just don't know how to combine those to VBA codes, so cell references in this line
    Please Login or Register  to view this content.
    Can be changed to the cell references that corresonds to the current week.

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: How to DRAW a line in VBA

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    03-07-2014
    Location
    Copenhagen
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: How to DRAW a line in VBA

    Hey Andy,

    Works just perfect!! I'm trying to get an idea what's going on in the code so I can learn something from it

    Again, Thank you very much!!!

    Regards,
    Michael

  10. #10
    Forum Contributor
    Join Date
    07-16-2009
    Location
    DutchLand
    MS-Off Ver
    Excel MacOS 16
    Posts
    161

    Re: How to DRAW a line in VBA

    Hi, I saw this old topic and the code. I did search for a similar problem and came here.
    I have one question about the code

    Please Login or Register  to view this content.
    this gives me a error in excel 2019. What is it doing?

    Thank you


    I did start a new thread about this topic here.
    Last edited by lord anubis; 12-24-2019 at 06:01 PM.

+ 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] Draw bol line if value in next cell is not the same as in previous
    By forfiett in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-09-2013, 09:46 AM
  2. Draw Line in Userform.
    By ebin charles in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-01-2010, 07:03 AM
  3. Draw line on userform
    By proepert in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-22-2010, 11:33 PM
  4. Can I get Excel to draw a line of best fit?
    By ronel in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 07-04-2005, 03:05 PM
  5. [SOLVED] How do I draw a line of best fit?
    By Gavin in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 04-15-2005, 05:06 PM

Tags for this Thread

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