请你帮我解决下面的公式?它给出了对象定义或app定义的错误。非常感谢。
Sub cellstovalues()
Sheets("Parsing").Select
Columns("B:B").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub
答案 0 :(得分:0)
您的代码在选择整个列B
时遇到问题。试试这个。这应该找到列中最后使用的单元格,然后复制并粘贴以将公式转换为您想要的值。
Sub cellstovalues()
Dim ws As Worksheet
Dim LastRow As Integer
Dim rng As Range
Set ws = ThisWorkbook.Sheets("Parsing")
With ws
LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
Set rng = .Range(.Cells(1, "B"), .Cells(LastRow, "B"))
End With
rng.Copy
rng.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub
答案 1 :(得分:0)
作为替代方案,您只需将值分配给范围的Value2
(或Value
)属性:
Sub cellstovalues()
With Sheets("Parsing")
With Intersect(.Range("B:B"), .UsedRange)
.Value2 = .Value2
End With
End With
End Sub
或针对特定范围:
Sub cellstovalues()
With Sheets("Parsing").Range("B1:C10")
.Value2 = .Value2
End With
End Sub