+ Reply to Thread
Results 1 to 3 of 3

Referencing an array within a For Next loop. Please help?

  1. #1
    Registered User
    Join Date
    09-11-2012
    Location
    York, England
    MS-Off Ver
    Excel 2007
    Posts
    39

    Referencing an array within a For Next loop. Please help?

    Hi Everyone,

    This is the problem: I have a range which stores information about a structure. Adjacent to the range is an array which stores the co-ordinates (x, y) for the structure. Each cell in the range determines a condition at the co-ordinates provided in the same row in the array, and I want VBA then to draw a shape at those co-ordinates depending on what was specified in the array.

    So essentially, I want to loop through the range, and depending on what is specified in the range, draw a shape at the co-ordinates provided in the array. Does this make sense?

    If anyone can think of good way to achieve this I would be very grateful. I have also provided my code (which gets rejected) as a reference.

    Thanks
    Jinxtt

    PHP Code: 
    Sub CreateSupports()

        
    Dim DemoC As Worksheet
        Set DemoC 
    Worksheets(1)
        
    Dim SupportRange As Range
        Set SupportRange 
    Range("D6:D8")
        
    Dim SupportType As String
        Dim Pinned 
    As Variant
        Dim Fixed 
    As Variant
        Dim Cell 
    As Variant
        
    For Each Cell In SupportRange
            Select 
    Case SupportType
                
    Case Pinned
                DemoC
    .Shapes.AddShape msoShapeOvalSupportRange.Offset(-20), SupportRange.Offset(-10), 1010
                
    Case Fixed
                DemoC
    .Shapes.AddShape msoShapeRectangle852004015
            End Select
        Next Cell
    End Sub 

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,093

    Re: Referencing an array within a For Next loop. Please help?

    Well, the fixed part of the code draws a blue box.

    Note that the Pinned option is referring to ranges rather than cells with values

    PHP Code: 
    ?SupportRange.Offset(-20).address
    $D
    $4:$D$6
    ?SupportRange.Offset(-10).address
    $D
    $5:$D$

    I'm guessing that you need to resize to (1,1).

    Please Login or Register  to view this content.
    Also, I can't see where SupportType, Pinned or Fixed are initialised. They're all just variants.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,093

    Re: Referencing an array within a For Next loop. Please help?

    Please Login or Register  to view this content.

    Regards, TMS

+ 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