道路养护信息统计中可用的一些代码

6 篇文章 0 订阅
1、清除数字格式

Sub ClearNumFormat()
    Dim i As Integer
    For i = 1 To Sheets.Count
        Sheets(i).Activate
        Range("E2").Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.NumberFormatLocal = "G/通用格式"
        Range("A1").Select
    Next i
End Sub


2、统计有效行

Sub RowsCount()
    Dim i, rwcnt As Integer
    rwcnt = 0
    For i = 1 To ActiveSheet.UsedRange.Rows.Count
        If Len(Cells(i, "C")) <> 0 Then
            rwcnt = rwcnt + 1
        End If
    Next i
    MsgBox rwcnt
End Sub


3、粘贴为纯文本

Sub PasteAsRawTxt()
    Dim i As Integer
    For i = 1 To Sheets.Count
        Sheets(i).Activate
        Cells.Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Application.CutCopyMode = False
        Range("A1").Select    
    Next i
End Sub


4、数字桩号转为文本桩号

Sub ZhuangHaoTXT()
    Dim i, j, rwcnt As Integer
    For i = 1 To Sheets.Count
        Sheets(i).Activate
        '统计有效行数
        rwcnt = 0
        For j = 1 To ActiveSheet.UsedRange.Rows.Count
            If Len(Cells(j, "C")) <> 0 Then
                rwcnt = rwcnt + 1
            End If
        Next j
    
        '格式化
        If rwcnt > 1 Then
            For j = 2 To rwcnt
                Cells(j, "B") = Format(Cells(j, "C").Value * 1000, "K&&&+&&&")
                Cells(j, "D") = Format(Cells(j, "E").Value * 1000, "K&&&+&&&")
            Next j
        End If
        Cells(1, 1).Select
    Next i
End Sub


5、其它

Sub DivideBy1000()
    Dim i, j, rwcnt As Integer
    For i = 1 To Sheets.Count
        Sheets(i).Activate
        '统计有效行数
        rwcnt = 0
        For j = 1 To ActiveSheet.UsedRange.Rows.Count
            If Len(Cells(j, "C")) <> 0 Then
                rwcnt = rwcnt + 1
            End If
        Next j
    
        '清除有效行以外的所有内容
        Rows(rwcnt + 1).Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.Clear
        
        'C列每个单元格数值除以1000
        If rwcnt > 1 Then
            For j = 2 To rwcnt
                Cells(j, "E").Value = Cells(j, "E").Value / 1000
            Next j
        End If
        Cells(1, 1).Select
    Next i
End Sub


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值