# moving shapes with wait method

#### tmischler

##### Well-known Member
Hi there,

Does anyone have any idea why the following code doesn't work?

Sub Macro4()

newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 1
waitTime = TimeSerial(newHour, newMinute, newSecond)

Static i As Long
For i = 1 To 10

ActiveSheet.Shapes("Rectangle 1").Select
Selection.ShapeRange.IncrementLeft -20
Application.Wait waitTime

Next i

End Sub

### Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use \$ signs: \$V\$2:\$Z\$99 will always point to V2:Z99, even after copying

#### tmischler

##### Well-known Member
Ok - first problem solved. Next problem is that the below code works if newSecond = Second(Now()) + 1 but not if newSecond = Second(Now()) + 0.5 any ideas anyone? Basically, I am just trying to make the shape move smoothly.

Sub Macro4()

Static i As Long

For i = 1 To 40
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 0.5

waitTime = TimeSerial(newHour, newMinute, newSecond)
ActiveSheet.Shapes("Rectangle 1").Select
Selection.ShapeRange.IncrementLeft -10
Application.Wait waitTime
Next i

End Sub

#### erik.van.geit

##### MrExcel MVP
Hi, tmischler,

try this

Code:
``````Sub speedregulator()
Do
delay = Timer + 0.05
Do Until Timer > delay
DoEvents
Loop
ActiveSheet.Shapes("Rectangle 1").Select
Selection.ShapeRange.IncrementLeft -1
Loop
End Sub``````

kind regards,
Erik

#### erik.van.geit

##### MrExcel MVP
Some furhter research brought me this.

great advantage: you don't need to select the shape
you can freely select cells and work on the sheet while your shape is moving

Code:
``````Sub speedregulator()
Do
delay = Timer + 0.05
Do Until Timer > delay
DoEvents
Loop
With ActiveSheet.Shapes("Rectangle 1")
.Left = .Left - 1
End With
Loop
End Sub``````

and playing around ...
Code:
``````Sub speedregulator()
d = 1.5
mind = 0 * d
maxd = 20 * d
ActiveSheet.Shapes("Rectangle 1").Left = maxd
Do
delay = Timer + 0.2
Do Until Timer > delay
DoEvents
Loop
With ActiveSheet.Shapes("Rectangle 1")
.Left = .Left - d
If .Left = mind Or .Left = maxd Then d = -d
Range("A1") = Format(.Left, "#")
End With
Loop
End Sub``````
still some Dim statements to add..
is this getting you further?

kind regards,
Erik

#### tmischler

##### Well-known Member
That's brilliant thanks Erik - would have taken me years to get there - thanks loads...

#### erik.van.geit

##### MrExcel MVP
You're welcome,

Just elaborating what the guys and girls learned me here
patience, you can get there too !

kind regards,
Erik

Replies
3
Views
654
Replies
1
Views
767
Replies
3
Views
333
Replies
7
Views
205
Replies
8
Views
713

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

1,152,117
Messages
5,768,218
Members
425,460
Latest member
Astros1243

### 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.

### Which adblocker are you using?

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

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