簡體   English   中英

使用VBA跨列復制文本

[英]Copy Text across Columns with VBA

我在excel工作簿中有一個列,其中包含一個“輸出示例”和另一個包含定義的列。 我需要輸出示例在定義中。 所以我寫了一個宏,在文本的末尾加上短語“Ex:”,然后復制相鄰列中的文本並在“Ex:”之后粘貼它。

   Sub Exampletransfer()
'
' Exampletransfer Macro
'
' Keyboard Shortcut: Ctrl+Shift+E
'
    Range("H2").Select
    ActiveCell.FormulaR1C1 = _
        "The age range, in years of a customer. Ex: "
    Range("I2").Select
    ActiveCell.FormulaR1C1 = "1-4"
    Range("H2").Select
    ActiveCell.FormulaR1C1 = _
        "The age range, in years of a customer. Ex: 1-4"
    Range("H3").Select
End Sub

我附上了一張照片。 我需要這個發生在整個專欄中。 我想我不明白如何讓宏繼續下一列。

我擁有 什么我需要什么

干得好。 確保在Range和Cells方法中更改數據的開始位置!

Sub AppendData()

Dim myRange As range
Dim myCell As range

'Change where you data starts. My practice started in B4, so that's
'what I used.
Set myRange = range("B4", Cells(Rows.count, "B").End(xlUp))


For Each myCell In myRange
    If myCell.Value <> "" Then
        myCell.Value = myCell.Value & " Ex: " & myCell.Offset(0, 1).Value
    End If
Next myCell


End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM