Consulting

Results 1 to 3 of 3

Thread: Deleting Ovals - Logic: If they are above row 70

  1. #1
    VBAX Contributor Daxton A.'s Avatar
    Joined
    Jun 2004
    Location
    Biloxi, Mississippi
    Posts
    143
    Location

    Deleting Ovals - Logic: If they are above row 70

    I have a worksheet that has a macro that's button activated and it draws an oval around the cell that is selected.
    I also have another button that databases all the information on the sheet and copies the cell with the oval.
    Now the problem comes when I select my Clear button macro because I have the code line:
    ActiveSheet.Ovals.Delete
    and that clears my database of ovals & I am needing the logic to delete
    the ovals down to row 69 and leave rows 70+ alone.

    Is it possible to achieve this goal without having another worksheet?

    Sub My_Circle()
        Dim x, y As Single, area, oldrange As Range
       
        'set starting cell
        Set oldrange = Selection.Cells(1)
              
        'rotate through areas - this allows multiple circles to be drawn
        For Each area In Selection.Areas
           With area
           ' x and y are numbers that are a function of the
           ' area's height and width
            x = .Height * 0.1
            y = .Width * 0.1
             ActiveSheet.Ovals.Add Top:=.Top - x, Left:=.Left - y, _
              Height:=.Height + 2 * x, Width:=.Width + 1.5 * y
            With ActiveSheet.Ovals(ActiveSheet.Ovals.Count)
                           .Interior.ColorIndex = xlNone
                           .ShapeRange.Line.Weight = 1.25
            End With
            End With
            
            'Bold the ActiveCell
            If ActiveCell.Font.Bold = True Then
                ActiveCell.Font.Bold = False
            Else
                ActiveCell.Font.Bold = True
            End If
            
        Next area
        
        oldrange.Select
        
    End Sub
    “All right now ya wise guy … Dance!”

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    Try this



    Option Explicit
    
    
    Sub DeleteOvalsAbove70()
        Dim iShapes As Long
        
        For iShapes = ActiveSheet.Shapes.Count To 1 Step -1
            With ActiveSheet.Shapes(iShapes)
                If .Type = msoAutoShape Then
                    If .AutoShapeType = msoShapeOval Then
                        If .TopLeftCell.Row < 70 Then
                            .Delete
                        End If
                    End If
                End If
            End With
            
        Next iShapes
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Contributor Daxton A.'s Avatar
    Joined
    Jun 2004
    Location
    Biloxi, Mississippi
    Posts
    143
    Location
    Right on Paul, worked beautifully...Thanks a bunch!!!
    “All right now ya wise guy … Dance!”

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •