热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

VBA不是单元格中的数据-VBAnotchangigdatainacell

thisisgoingtobesomethingreallyreallysilly!ihavethiscode:这真是太傻了!我有这个代码:PublicSubSort

this is going to be something really really silly! i have this code:

这真是太傻了!我有这个代码:

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

the code runs fine but the data on the cells does not get changed accordingly. if use debug.print it does print the results that i am looking for. please help!

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

here is a sample of the data:

这是一个数据样本:

1984000
40000000
230000
230000
230000
1984000
230000
16000000

and this is what the debug.print gives me which is the correct result but not showing on the actual cells (this is just an example and not respective to the data provided):

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

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

i still need to add the IF statement for the kb part but i have got that covered.

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

1 个解决方案

#1


3  

It's not entirely clear what your logic is meant to do, but it looks like one those ElseIfs should be a separate If block.

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

columnC doesn't seem to be doing anything.

columnC似乎没有做任何事情。

Is this more what you were looking for?

这更像你在寻找什么?

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

推荐阅读
author-avatar
zhouib8oevlap
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有