在VBA中保持excel的自动格式化

我有这个代码是从另一个工作表中提取值。 这些值是TEXT,但在提取Excel后,无论如何将它们转换为数字,即使将列设置为文本格式,即使使用

Format( value , "#") 

问题是,他们是大数字,它正在改变15位数以上的任何数字为0,我需要的数字,因为它们是。

它们在参考栏(j,3)中不被剪切,所以在这个过程中会发生变化

 Dim i, col1, col2 As Integer i = 2 col1 = 4 col2 = 5 For j = 2 To 2205 If Cells(j, 3).Value <> "" Then If Len(Cells(j, 3)) = 20 Then Cells(i, col1).Value = Format(Cells(j, 3).Value, "#") Cells(i, col2).Value = Cells(j, 3).Row Cells(j, 3).Value = "" i = i + 1 End If End If Next j i = 2 col1 = col1 + 2 col2 = col2 + 2 

Excel有15位精度的限制,所以小数两边的15位以上的数字将不会以所需的精度进行存储。 您是否尝试在插入值之前设置单元格格式? 在设置值之前Cells(i, col1).NumberFormat = "@"请使用“线条” Cells(i, col1).NumberFormat = "@"

  Dim i, col1, col2 As Integer i = 2 col1 = 4 col2 = 5 For j = 2 To 2205 If Cells(j, 3).Value <> "" Then If Len(Cells(j, 3)) = 20 Then Cells(i, col1).NumberFormat = "@" Cells(i, col1).Value = Format(Cells(j, 3).Value, "#") Cells(i, col2).Value = Cells(j, 3).Row Cells(j, 3).Value = "" i = i + 1 End If End If Next j i = 2 col1 = col1 + 2 col2 = col2 + 2