我尝试搜索此问题,但无法找到解决方案 我正在做一个VBA脚本,将一些数字从另一个电子表格(.xls)复制到一个新的(.xlsx)
这些数字都散布在纸张上,所以我制作了这个剧本:
Sub ColetaDados(planilha, banco_base):
'Function to copy and paste
Workbooks(planilha).ActiveSheet.Range("W1").Select
ActiveCell.End(xlDown).Select
ActiveCell.Offset(0, -12).Select
'finds the last row I have to work with
i = 0
Do While i < 3
ActiveCell.End(xlUp).Select
i = i + 1
Loop
endrow = ActiveCell.Row
'Starts doing the copying and pasting
'This copies the header
Range("V1").Select
ActiveCell.End(xlDown).Select
Range(ActiveCell, ActiveCell.Offset(0, -20)).Copy
Workbooks(banco_base).Activate
Cells(1, 1).Select
ActiveSheet.Paste
'this copies the first value selection
Workbooks(planilha).Activate
ActiveCell.Offset(2, 0).Select
Range(ActiveCell, ActiveCell.Offset(0, -20).End(xlDown)).Copy
Workbooks(banco_base).Activate
Cells(2, 1).End(xlUp).Select
ActiveCell.Offset(1, 0).Select
' since this sub goes in a For loop that iterates on 4 workbooks
' I created this if to avoid pasting over the wrong cell
If IsEmpty(ActiveCell.Value) Then
ActiveSheet.Paste
Else
ActiveCell.End(xlDown).Offset(1, 0).Select
ActiveSheet.Paste
End If
' This iteration copies over the other selections
Do While currentrow <= endrow
Workbooks(planilha).Activate
ActiveCell.End(xlDown).Select
ActiveCell.Offset(5, 0).Select
currentrow = ActiveCell.Row
Range(ActiveCell, ActiveCell.Offset(0, -20).End(xlDown)).Copy
Workbooks(banco_base).Activate
Cells(2, 1).End(xlDown).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
Loop
End Sub
我得到以下结果: 作为数字的每个单元格都被粘贴为文本,末尾有三个零。示例:11变为11000
我无法弄清楚发生了什么。我检查了.xls
文件并确认正确插入了值,单元格上没有空格或其他字符。我也尝试使用PasteSpecial xlPasteValues
,但同样的事情发生了。
知道可能会发生什么吗?