+ Reply to Thread
Results 1 to 4 of 4

Generating shapes in excel

Hybrid View

  1. #1
    Registered User
    Join Date
    11-08-2013
    Location
    Ireland
    MS-Off Ver
    Excel 2010
    Posts
    45

    Generating shapes in excel

    I'm trying to produce some simple shapes in a workbook when a button is pressed. Ill be adding more code to later on to manipulate the shapes.

    I have a list in the worksheet cell AA1 to AA5 as follows Type Name
    bar __bar_2 20 120
    bar __bar_1 10 100
    point __point_1 2 2
    pin __pin_1 8 2

    The bars appear in the worksheet fine but when I added code for the point and pin the code wont run

    The code is as follows

    Private Sub CommandButton1_Click()
    list_top = "AA1"
    For i = 1 To 100000
    shape_type = Range(list_top).Offset(i, 0).Value
    If shape_type = "" Then Exit Sub

    Select Case shape_type
    Case "bar"
    new_bar Range(list_top).Offset(i, 1).Value, Range(list_top).Offset(i, 2).Value, Range(list_top).Offset(i, 3).Value
    Case "point"
    new_point Range(list_top).Offset(i, 1).Value, Range(list_top).Offset(i, 2).Value, Range(list_top).Offset(i, 3).Value
    Case "pin"
    new_pint Range(list_top).Offset(i, 1).Value, Range(list_top).Offset(i, 2).Value, Range(list_top).Offset(i, 3).Value
    End Select
    Next i
    End Sub

    with module

    Public Sub new_bar(ByVal bar_name As String, ByVal bar_width As Double, bar_length_pin_to_pin As Double)
    ActiveSheet.Shapes("_bar").Duplicate
    DoEvents
    ActiveSheet.Shapes(ActiveSheet.Shapes.Count).Name = bar_name
    ActiveSheet.Shapes(bar_name).Height = bar_width
    ActiveSheet.Shapes(bar_name).Width = bar_width + bar_length_pin_to_pin
    End Sub

    Public Sub new_point(ByVal point_name As String)
    ActiveSheet.Shapes("_point").Duplicate
    DoEvents
    ActiveSheet.Shapes(ActiveSheet.Shapes.Count).Name = point_name
    ActiveSheet.Shapes(point_name).Height = point_width
    ActiveSheet.Shapes(point_name).Width = point_diameter
    End Sub

    Public Sub new_pin(ByVal pin_name As String, ByVal pin_diameter As Double)
    ActiveSheet.Shapes("_pin").Duplicate
    DoEvents
    ActiveSheet.Shapes(ActiveSheet.Shapes.Count).Name = pin_name
    ActiveSheet.Shapes(point_name).Height = pin_width
    ActiveSheet.Shapes(point_name).Width = pin_width
    End Sub

    Not sure what the problem is, probably something simple? I haven't been using VBA very long
    Thanks Paul

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

    Re: Generating shapes in excel

    Try putting Option Explicit at the top of the code module, and then declaring your variables. That will help you find your typo.
    Last edited by shg; 12-11-2013 at 03:31 PM.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    11-08-2013
    Location
    Ireland
    MS-Off Ver
    Excel 2010
    Posts
    45

    Re: Generating shapes in excel

    Thanks

    There was a number of variables I hadn't declared.

    Paul

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

    Re: Generating shapes in excel

    You're welcome.

+ 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] followup top shapes as one colour, exclude 2 shapes
    By deancorleone in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-01-2013, 02:14 PM
  2. Shapes based on Cell Data, Golf Score card data that shows shapes around scores
    By BiggDC1 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-12-2012, 12:42 PM
  3. How To Move Shapes From Another Shapes? (floating shapes)
    By MarcLev in forum Word Programming / VBA / Macros
    Replies: 2
    Last Post: 10-04-2009, 04:04 PM
  4. Excel Shapes
    By Jason Zischke in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-06-2006, 09:40 AM
  5. [SOLVED] How can i get more 3D shapes for Auto shapes in excel?
    By Ajey in forum Excel General
    Replies: 0
    Last Post: 03-03-2005, 06:06 AM

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