VBA不会改变单元格中的数据

这将是非常愚蠢的事情! 我有这个代码:

Public Sub SortMyData() Dim i As Integer Dim N_Values As Integer Dim columnC As String N_Values = Cells(Rows.Count, 2).End(xlUp).Row For i = 6 To N_Values Cells(i, 3).NumberFormat = "0" If Cells(i, 2).NumberFormat <> "0.0%" Then Cells(i, 2).NumberFormat = "0.0%" Cells(i, 2).Value = Cells(i, 2).Value / 100 ElseIf (Cells(i, 3).Value) > 1000000 Then columnC = (Cells(i, 3).Value / 1000000) & "Mb" ElseIf Cells(i, 3).Value = Null Then Cells(i, 3).Value = 0 Else Cells(i, 2).Value = Cells(i, 2).Value Cells(i, 3).Value = Cells(i, 3).Value End If Next i End Sub 

代码运行良好,但单元格上的数据不会相应地改变。 如果使用debug.print,它会打印我正在查找的结果。 请帮忙!

这里是一个数据的样本:

 1984000 40000000 230000 230000 230000 1984000 230000 16000000 

这是debug.print给我的是正确的结果,但没有显示在实际的单元格上(这只是一个例子而不是提供的数据):

 2.048Mb 1.984Mb 230kb 16Mb 230kb 16Mb 8Mb 2.007Mb 230kb 

我仍然需要为kb部分添加IF语句,但我已经得到了覆盖。

目前还不完全清楚你的逻辑是做什么的,但是看起来ElseIfs应该是一个单独的If块。

C列似乎没有做任何事情。

这更多是你在找什么?

 Public Sub SortMyData() Dim i As Integer Dim N_Values As Integer N_Values = Cells(Rows.Count, 2).End(xlUp).Row For i = 6 To N_Values Cells(i, 3).NumberFormat = "0" If Cells(i, 2).NumberFormat <> "0.0%" Then Cells(i, 2).NumberFormat = "0.0%" Cells(i, 2).Value = Cells(i, 2).Value / 100 Else Cells(i, 2).Value = Cells(i, 2).Value End If If (Cells(i, 3).Value) > 1000000 Then Cells(i, 3).Value = (Cells(i, 3).Value / 1000000) & "Mb" ElseIf Cells(i, 3).Value = Null Then Cells(i, 3).Value = 0 End If Next i End Sub