vba - 使文本在单行的一系列单元格中从右到左爬行

标签 vba excel

这是一个棘手的问题!

我想让一个单词或短语从右到左在单行中的 30 个单元格范围内爬行,在一个循环中连续重复,并且在移动时足够慢以阅读。

任何人都可以帮助提供代码!

我已经设法一次完成一个字符,但我想让整个单词爬行,每个单元格一个字符。

这是迄今为止我面临的最艰难的 vba 挑战!

提前致谢。

这是我的基本版本的代码片段:

For CounterTxt = 1 To textLngt

    chaseEnd = chaseEnd + 1

    For CounterChase = chaseBeg To chaseEnd - 1 Step -1

        Worksheets("Sheet1").Cells(7, CounterChase + 1).Value = "" ' deleats previous chase position while running.
        Worksheets("Sheet1").Cells(7, CounterChase).Value = Mid(MyText, CounterTxt, 1)

        Sleep 20

    Next CounterChase

Next CounterTxt

最佳答案

Sub March()
    Dim str As String
    str = "Hello World"

    Dim rng As Range
    Set rng = Worksheets("Sheet1").Range("A1:Z1")

    rng.ClearContents

    Dim secondstr As String
    secondstr = str & Application.Rept(" ", rng.Cells.Count)

    Dim vlue As String
    vlue = StrConv(secondstr, vbUnicode)

    Dim substr() As String
    substr = Split(Left(vlue, Len(vlue) - 1), vbNullChar)


    Dim i As Long
    For i = rng.Cells.Count + rng.Column - 1 To rng.Column Step -1
        If i = rng.Column Then
            Dim j As Long
            For j = 0 To Len(str)
                Dim k As Long
                For k = 1 To Len(str) + 1
                    rng.Cells(1, k) = substr(j + k - 1)
                Next k
                Application.Wait Now() + 1 / (24 * 60 * 60#)
            Next j

        Else
            rng.Cells(1, i).Resize(, Application.Min(Len(secondstr), rng.Cells.Count - i + 1)) = substr
            Application.Wait Now() + 1 / (24 * 60 * 60#)
        End If

    Next i

    March


End Sub

关于vba - 使文本在单行的一系列单元格中从右到左爬行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52120419/

相关文章:

excel - 如何使用 VBA 自动扩展图表的范围?

由于内存碎片,Excel 2013 崩溃

excel - Laravel Excel 工作正常,但文件无法打开

vba - 记录集.movefirst "Rowset position cannot be restarted"

excel - 如何使用 Excel VBA 最大化特定显示器上的窗口?

excel - 无法将 1 添加到当前单元格值

linq - 汇总 VBA 集合中的记录

将单个语句包装在 try except block 中的 Python 干净方法

Excel图表自动调整轴原点大小

vba - 将范围从 Excel 粘贴到 PowerPoint,同时保持格式设置