VBA-dropdown list influencing shape location

inesguimaraescosta

New Member
Joined
Oct 25, 2017
Messages
1
I have this code that creates text boxes on worsheet(1) when I enter something in Worksheet(1) A1 to A30. At the moment the boxes are created on top of each other. Now I want to add a new feature: I want the place of the texboxes to be choosen acoordingly, when I choose one option of a dropdown list. In Worksheet(1).column(2) I will have a dropdown list that has three options: blue, green, yellow and those options are linked to a place in worksheet(2), so if in B1 I choose green the textbox with the text from A1 should appear in the space of green (A1 to H1), but if I choose yellow the texbox should appear in A10 to H10. How can I do this? Thank you
Code:
<code>Sub removercaixas(strName As String)

    Dim shp As Shape
    For Each shp In Worksheets(2).Shapes
        If shp.Type = msoTextBox And shp.Name = strName Then shp.Delete
    Next shp

End Sub
Sub criarcaixastexto(strName As String)

    Dim wsActive As Worksheet
    Dim box As Shape

    Set wsActive = Worksheets(2)
    Set box = wsActive.Shapes.AddTextbox(msoTextOrientationHorizontal, 20, 20, 100, 50)

    box.TextFrame.Characters.Text = Worksheets(1).Range(strName).Value
    box.Name = strName

End Sub
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub
    Select Case Target.Address
        Case "$A$1", "$A$2", "$A$3","$A$4","$A$5", "$A$6", "$A$7", "$A$8", "$A$9" "$A$10", "$A$11", "$A$12", "$A$13", "$A$14", "$A$15", "$A$16", "$A$17", "$A$18", "$A$19", "$A$20", "$A$21", "$A$22", "$A$23", "$A$24", "$A$25", "$A$26", "$A$27", "$A$28", "$A$29", "$A$30"
            removercaixas (Target.Address)
            If Len(Target) > 0 Then criarcaixastexto (Target.Address)
        Case Else
            Exit Sub
    End Select

End Sub</code>
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top