如何使宏适用于 A 列的所有单元格?这样就可以一次粘贴到多个单元格中并转换数据。我需要这个才能一次转换多个数据。
我有这个宏:
Option Compare Text
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
If Target.Column <> 1 Then Exit Sub
Dim v As Variant
v = Split(Target, " ")
If UBound(v) <> 1 Then Exit Sub
If Right(Target, 1) <> "m" Then
Target = v(1) & " " & v(0)
End If
End Sub
此宏将数据转换为(任意数字)m和(任意数字)M在右边。
例如:
L3 280M
500m FMA
Nest 475m
340m Pr6
720M uT10
etc.
转换成:
L3 280M
FMA 500m
Nest 475m
Pr6 340m
uT10 720M
etc.
答案1
也许是这样?
Option Explicit
Option Compare Text
Private Sub Worksheet_Change(ByVal Target As Range)
Dim oCell As Range
Dim v As Variant
If Application.WorksheetFunction.CountA(Target) < 1 Then Exit Sub
For Each oCell In Target.Cells
If oCell.Column = 1 Then
v = Split(oCell.Text, " ")
If UBound(v) = 1 Then
If Right(v(1), 1) <> "m" Then
oCell.Value = v(1) & " " & v(0)
End If
End If
End If
Next oCell
End Sub