VBA to position text box based on specific cell value

platypus007

New Member
Joined
Oct 24, 2019
Messages
19
Office Version
  1. 2016
Platform
  1. Windows
Hi, I need help: I have only one row (lets call it row10) with values from 1 to 5. I need to automatically place text box to cell with value 3 (into row10).Now I have this VBA for exact cell...How can I do it?

VBA Code:
Public Sub Area33A()
    MoveShape ActiveSheet.Shapes("kriz"), Range("v43")
End Sub

Private Sub MoveShape(ByVal shp As Excel.Shape, ByVal Target As Excel.Range)
    shp.IncrementLeft -(shp.TopLeftCell.Left - Target.Left)
    shp.IncrementTop -(shp.TopLeftCell.Top - Target.Top)
End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
The below code searches within row 10 for any cell containing the value 2, stops at the first cell found and moves your shape.

VBA Code:
Private Sub MoveShape(ByVal shp As Excel.Shape, ByVal Target As Excel.Range)
     shp.Top = Target.Top
     shp.Left = Target.Left
End Sub

Public Sub platypus007()
    Const cValueToSearchFor As Long = 2
    Dim c As Range
    For Each c In ActiveSheet.Rows(10)
        If c.Value = cValueToSearchFor Then
            MoveShape ActiveSheet.Shapes("kriz"), c
            Exit For
        End If
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,926
Messages
6,122,306
Members
449,079
Latest member
juggernaut24

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