Results 1 to 8 of 8

Thread: Delete Rows which values < 500 and Rounding Values > 500 VB.net?

Threaded View

  1. #1

    Thread Starter
    Banned
    Join Date
    Apr 2020
    Location
    https://t.me/pump_upp
    Posts
    61

    Delete Rows which values < 500 and Rounding Values > 500 VB.net?

    Dear All

    0


    I have a Column in excel which has numbers with Decimals, Which if they are less than 500 I want to delete and if they are bigger than 500, i want to round the number to become without decimals.

    I use the below code which does not give any errors but does not do the job, Please Check this Code:

    Code:
     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 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
    Your help is Highly Appreciated, Thanks

    Moheb Labib
    Last edited by meho2020; Sep 7th, 2020 at 03:22 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width