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>