【发布时间】:2019-10-02 04:08:30
【问题描述】:
我正在尝试将一串数字转换为 9 位文本。每次运行时,列的长度都会有所不同。
尝试使用与查找 LastRow 类似的方法。
Sub Macro3()
'
Dim LastRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Data Validation")
Sheets("Data Validation").Select
Cells.Replace What:="-", Replacement:="", LookAt:=xlPart, SearchOrder:= _
xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
LastRow = ws.Cells.find(What:="*", After:=ws.Cells(1, 1),
LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious,
MatchCase:=False).Row
Set rng = Cells(LastRow, 15)
Range("O2").Select
ActiveCell.FormulaR1C1 = "=TEXT(RC[-4],""000000000"")"
Range("O2").Select
Selection.AutoFill Destination:=Range("O2:rng")
End Sub
我希望我的文本格式可以延伸到现有数字的整个列。目前我收到了 Object _Global 的 Method Range failed 错误消息。
【问题讨论】:
-
Range("O2:O" & LastRow).FormulaR1C1 = "=TEXT(RC[-4],""000000000"")"不需要Select或AutoFill