Consulting

Results 1 to 3 of 3

Thread: Problem with Macro

  1. #1

    Post Problem with Macro

    Hi guys,
    I'm experiencing some trouble with Mcro code. I'm trying to write macro which will be run only on shapes ( checkboxes or option buttons) that exist within the range of selected cell or cells.
    for example:
    If I select cell that " contains" a shape, then I run macro - it will only change the colour of of shape range ( that field around the shape when we select it)

    as for now I have sth like this: (but it's not working)

    Public Sub check()


    Dim RngClrBut As Range
    Dim ObClrBut As Shape




    If Selection.Count >= 1 Then
    Set RngClrBut = Selection.Cells.SpecialCells(xlVisible)
    On Error Resume Next
    For Each ob In ActiveSheet.Shapes
    If Not Application.Intersect(ob.TopLeftCell, rg) Is Nothing Then

    ActiveSheet.CheckBoxes(ObClrBut.Name).Interior.ColorIndex = 10
    ActiveSheet.OptionButtons(ObClrBut.Name).Interior.ColorIndex = 10
    End If
    End If

    End Sub

    Any help will be much appreciated.

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    ry this:
    Public Sub blah()
    Dim RngClrBut As Range, Ob
    If Selection.Count > 0 Then
      Set RngClrBut = Selection.SpecialCells(xlVisible)
      For Each Ob In ActiveSheet.CheckBoxes
        If Not Application.Intersect(Ob.TopLeftCell, RngClrBut) Is Nothing Then Ob.Interior.ColorIndex = 10
      Next Ob
      For Each Ob In ActiveSheet.OptionButtons
        If Not Application.Intersect(Ob.TopLeftCell, RngClrBut) Is Nothing Then Ob.Interior.ColorIndex = 10
      Next Ob
    End If
    End Sub
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    Works Perfect!

    Thank you so much!

Tags for this Thread

Posting Permissions

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