EXCEL不连续单元格拷贝和修改

对现在订单处理的操作感到不便,忽然想起可以用VBA来实现想法。为啥早没想到呢!

网上借鉴了些代码。

Sub 选取区域追加文本()
Dim c As Range
Dim add As String
add = InputBox(prompt:=" 请输入追加文本:", Default:="-M1")
For Each c In Selection
Debug.Print c.Address
c = c & add
Next
End Sub

—————————————————————————————–

Sub 不连续区域文本黏贴()
‘获取黏贴板数据
Dim MyData As DataObject
Set MyData = New DataObject
MyData.GetFromClipboard
Arr = Split(MyData.GetText(1), Chr(13) + Chr(10))

‘For i = 0 To UBound(arr)
‘Debug.Print arr(i)
‘Next i

‘将数据(数组)赋值到选定单元格
Dim c As Range
Dim add As String
i = -1
For Each c In Selection
    i = i + 1
        c = Arr(i)
        Debug.Print Arr(i)
Next
Set MyData = Nothing

End Sub

—————————————————————————————–

Option Base 1
‘将选中的不连续单元格赋值到数组
Sub test()
    Dim Arr() As Variant
    Dim i As Long
    For Each cl In Selection
        i = i + 1
        ReDim Preserve Arr(i)
         Arr(i) = cl
    Next cl

‘在这里你就可以使用ARR数组了
End Sub