VBA复制string并粘贴科学记数法

我在下面的代码有问题。 该代码应该复制长string。 源文件包含这个内容作为string。 这是约50个字符长。 有数字和字母混合。

问题在于,对于某些粘贴的范围,它们是以其他function无法查看的科学记号。

这是代码的相关部分

For i = 1 To Columns.Count If Left(ActiveWorkbook.Sheets(1).Cells(7, i).Value, 4) = "1068" Then ActiveWorkbook.Sheets(1).Range(ActiveWorkbook.Sheets(1).Cells(7, i).End(xlUp), ActiveWorkbook.Sheets(1).Cells(7, i).End(xlDown)).Copy _ Destination:=ThisWorkbook.Sheets(1).Cells(Rows.Count, 1).End(xlUp).Offset(1, 0) End If Next i 

有没有办法只粘贴这个范围的值? 我已经尝试了方法“粘贴值”,但得到了VBA错误消息

而不是:

 ActiveWorkbook.Sheets(1).Range(ActiveWorkbook.Sheets(1).Cells(7, i).End(xlUp), ActiveWorkbook.Sheets(1).Cells(7, i).End(xlDown)).Copy _ Destination:=ThisWorkbook.Sheets(1).Cells(Rows.Count, 1).End(xlUp).Offset(1, 0) 

做这个,而不是:

 ActiveWorkbook.Sheets(1).Range( _ ActiveWorkbook.Sheets(1).Cells(7, i).End(xlUp), _ ActiveWorkbook.Sheets(1).Cells(7, i).End(xlDown) _ ).Copy ThisWorkbook.Sheets(1).Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues Application.CutCopyMode = False 

另外,我提出了一些使代码更清晰的方法:

 Dim rngCopyFrom as Range Dim rngCopyTo as Range Set rngCopyFrom = ActiveWorkbook.Sheets(1).Range( _ ActiveWorkbook.Sheets(1).Cells(7, i).End(xlUp), _ ActiveWorkbook.Sheets(1).Cells(7, i).End(xlDown) _ ) Set rngCopyTo = ThisWorkbook.Sheets(1).Cells(Rows.Count, 1).End(xlUp).Offset(1, 0) rngCopyFrom.Copy rngCopyTo.PasteSpecial Paste:=xlPasteValues Application.CutCopyMode=False 

更改单元格的格式。

您可以使用以下方法进行更正:

 .NumberFormat = "##0_)" 

以下是如何pipe理格式的示例:

 ActiveWorkbook.Sheets(1).Cells(7, i).NumberFormat = "##0_)" ActiveWorkbook.Sheets(1).Range(ActiveWorkbook.Sheets(1).Cells(7, i).End(xlUp), ActiveWorkbook.Sheets(1).Cells(7, i).End(xlDown)).NumberFormat = "##0_)" ThisWorkbook.Sheets(1).Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).NumberFormat = "##0_)" 

一旦格式化被改变,科学记数法就不应该显示。

要将数字string转换为数字值:

 t = ActiveWorkbook.Sheets(1).Range(Cells(7, I).End(xlUp), _ ActiveWorkbook.Sheets(1).Cells(7, I).End(xlDown) _ ).Value Set dest = ThisWorkbook.Sheets(1).Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Cells(1).Resize(UBound(t)) dest.NumberFormat = "" dest.FormulaLocal = t