Excel 删除包含值的行<;500和舍入值>;500 VB.net?

Excel 删除包含值的行<;500和舍入值>;500 VB.net?,excel,vb.net,criteria,Excel,Vb.net,Criteria,我在excel中有一个列,其中有带小数的数字,如果它们小于500,我想删除,如果它们大于500,我想将数字四舍五入为不带小数 我使用以下代码,该代码没有给出任何错误,但不起作用,请检查此代码: Private Sub DeleteCells_T08() Dim xl As New Excel.Application Dim wb As Excel.Workbook Dim ws As Excel.Worksheet Dim

我在excel中有一个列,其中有带小数的数字,如果它们小于500,我想删除,如果它们大于500,我想将数字四舍五入为不带小数

我使用以下代码,该代码没有给出任何错误,但不起作用,请检查此代码:

    Private Sub DeleteCells_T08()
        Dim xl As New Excel.Application
        Dim wb As Excel.Workbook
        Dim ws As Excel.Worksheet
        Dim Rng As Excel.Range
        Dim i As Integer
        Dim currentcell As Excel.Range
        Dim lRow As Long
        xl.DisplayAlerts = False
        wb = xl.Workbooks.Open("C:\Patches\Main_Master_VB.xlsm")
        ws = wb.Sheets("Result_T08")
        With ws
            lRow = .Range("B" & .Rows.Count).End(Excel.XlDirection.xlUp).Row
        End With
        Rng = ws.Range("B2", "B" & lRow)
        For i = Rng.Rows.count To 1 Step -1
            If Rng.Cells(i).Value < 500 Then
                Rng.Rows(i).EntireRow.Delete
            Else
                For Each currentcell In Rng
                    currentcell.Value = xl.WorksheetFunction.Round(currentcell.Value, 0)
                Next currentcell
            End If
        Next i
        xl.DisplayAlerts = True
    End Sub
Private Sub-deleteCell_T08()
Dim xl作为新的Excel.Application
将wb设置为Excel.工作簿
将ws设置为Excel.Worksheet
尺寸为Excel.Range
作为整数的Dim i
将currentcell设置为Excel.Range
暗淡的光线和长的一样
xl.DisplayAlerts=False
wb=xl.Workbooks.Open(“C:\Patches\Main\u Master\u VB.xlsm”)
ws=wb.Sheets(“结果_T08”)
与ws
lRow=.Range(“B”和.Rows.Count).End(Excel.XlDirection.xlUp).Row
以
Rng=ws.范围(“B2”、“B”和lRow)
对于i=Rng.Rows.count到1步骤-1
如果Rng.Cells(i).值<500,则
Rng.Rows(i).EntireRow.Delete
其他的
对于Rng中的每个currentcell
currentcell.Value=xl.WorksheetFunction.Round(currentcell.Value,0)
下一个电流单元
如果结束
接下来我
xl.DisplayAlerts=True
端接头
非常感谢你的帮助,谢谢

我找到了答案

    Private Sub DeleteCells()
        Dim xl As New Excel.Application
        Dim wb As Excel.Workbook
        Dim ws As Excel.Worksheet
        Dim Rng As Excel.Range
        Dim lRow As Integer
        Dim i As Integer
        xl.DisplayAlerts = False
        wb = xl.Workbooks.Open("C:\Patches\Main_Master_VB.xlsm")
        ws = wb.Sheets("Result_T08")
        With ws
            lRow = .Range("B" & .Rows.Count).End(Excel.XlDirection.xlUp).Row
        End With
        Rng = ws.Range("B2", "B" & lRow)
        For i = lRow To 1 Step -1
            Dim line As Excel.Range
            line = CType(Rng.Cells(i, 1), Excel.Range)
            If CDbl(line.Value) < 500 Then
                line.EntireRow.Delete()
            Else
                line.Value = xl.WorksheetFunction.Round(CDbl(line.Value), 0)
            End If
        Next
        xl.DisplayAlerts = True
        wb.Close(SaveChanges:=True)
        xl.Quit()
    End Sub 
Private Sub-DeleteCells()
Dim xl作为新的Excel.Application
将wb设置为Excel.工作簿
将ws设置为Excel.Worksheet
尺寸为Excel.Range
Dim lRow作为整数
作为整数的Dim i
xl.DisplayAlerts=False
wb=xl.Workbooks.Open(“C:\Patches\Main\u Master\u VB.xlsm”)
ws=wb.Sheets(“结果_T08”)
与ws
lRow=.Range(“B”和.Rows.Count).End(Excel.XlDirection.xlUp).Row
以
Rng=ws.范围(“B2”、“B”和lRow)
对于i=L,请转至1步骤-1
以Excel.Range显示的尺寸线
line=CType(Rng.Cells(i,1),Excel.Range)
如果CDbl(线值)<500,则
line.EntireRow.Delete()
其他的
line.Value=xl.WorksheetFunction.Round(CDbl(line.Value),0)
如果结束
下一个
xl.DisplayAlerts=True
wb.Close(保存更改:=True)
xl.Quit()
端接头

但不起作用
-显然它起了作用?什么是
Rng.Address
,最后是
i
是什么?@GSerg,计数器的i和小于500的125.50等数字不是deleted@GSerg,请注意,此代码在VBA中运行良好,但我将应用程序传输到VB.net时遇到的问题,VBA接受将Rng声明为variant以解决问题,但我无法在VB.net中声明variant,我尝试了Object,VariantType,但它不起作用,谢谢我编辑了上面的代码,使其与正在工作的VBA代码类似。请同时显示您的VB.net代码