Inserting text and loops

Krystn

New Member
Joined
Nov 6, 2015
Messages
14
Hi beginner here and I'm afraid I have myself in a pickle,

I'm attempting to take a string from a single cell in one worksheet to a single cell in another, one character at a time, with brief pauses in between. Intending ultimately to give the user the animated effect of text appearing as if it were being 'typed live'.

At the moment this is how my code looks, could anybody please explain how I am going wrong.

Code:
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
[HR][/HR]
Sub Typing()

Dim srctxt As Range
Set srctxt = Range("A1").Value
    
Dim dsttxt As Range
Set dsttxt = Sheets("Message").Range("A1").Value

Dim lngth As Integer
    lngth = Len(dsttxt)

Dim i As Long
 
        For i = 1 To lngth
            
            dsttxt = dsttxt & Mid(srctxt, i, 1)
            
            DoEvents
            Sleep 75
            DoEvents
        Next
End Sub

Thanks in advance,
Krystn
 
I had to make a few changes to your code. I removed .Value from the Range assignments. Others are highlighted in red:

Rich (BB code):
Sub Typing()

    Dim srctxt As Range
    Set srctxt = Range("A1")
    
    Dim dsttxt As Range
    Set dsttxt = Sheets("Message").Range("A1")


    Dim lngth As Integer
    lngth = Len(srctxt.Value)


    Dim i As Long
    Sheets("Message").Activate
    For i = 1 To lngth
            
        dsttxt.Value = dsttxt.Value & Mid(srctxt.Value, i, 1)
        
        DoEvents
        Sleep 75
        DoEvents
    Next i
End Sub
 
Upvote 0

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