Results 1 to 5 of 5

Thread: Remove records with 0 values

  1. #1
    Lively Member
    Join Date
    Jan 12
    Posts
    71

    Remove records with 0 values

    Hi All,

    I am writing data from Access to excel. There are few records with 0 values. How to remove those records?

    Below the code used to export data from Access to Excel.

    Code:
    Dim TempString As String
    
        Set objXLApp = CreateObject("Excel.Application")
        wb = "F:\MyDoc\Weekly MI Automation\" & sTeamRegionName & Left(Date, 2) & Mid(Date, 4, 2) & Right(Date, 4) & "_" & Left(Time, 2) & Mid(Time, 4, 2) & ".xlsx"
        
        Set objXLWorkbook = objXLApp.Workbooks.Add 'Will Create a new workbook
        Set objXLSheet = objXLWorkbook.Worksheets(1) 'Will create a new worksheet
        'objXLSheet.Name = sTeamRegionName 'Rename the worksheet
        'Set Wkb = AppExcel.Workbooks.Open(excelname)
        
        objXLApp.Visible = True 'Makes the spreasheet visible. False will let you open it behind the scenes
    
        For count = 1 To recount
            ColumnStart = 1
            objXLSheet.Cells(RowStart, ColumnStart) = rsTmp![Banker]
            ColumnStart = ColumnStart + 1
            objXLSheet.Cells(RowStart, ColumnStart) = rsTmp![RevenueYTD]
            ColumnStart = ColumnStart + 1
            objXLSheet.Cells(RowStart, ColumnStart) = rsTmp![AnnuRevenue]
            ColumnStart = ColumnStart + 1
            objXLSheet.Cells(RowStart, ColumnStart) = rsTmp![RevenueTCY]
            ColumnStart = ColumnStart + 1
            objXLSheet.Cells(RowStart, ColumnStart) = rsTmp![RevenuePFY]
            ColumnStart = ColumnStart + 1
            objXLSheet.Cells(RowStart, ColumnStart) = rsTmp![AnnuVsBud]
            ColumnStart = ColumnStart + 1
            objXLSheet.Cells(RowStart, ColumnStart) = rsTmp![AnnuVsPFYRev]
            ColumnStart = ColumnStart + 1
            ..............
            ..............
            ..............
            ..............
            ..............
    
            ColumnStart = ColumnStart + 1
            objXLSheet.Cells(RowStart, ColumnStart) = rsTmp![AnnuActRatio]
    
            If rsTmp.EOF Then Exit For
            RowStart = RowStart + 1
            rsTmp.MoveNext
        Next count
    
        rsTmp.Close
        Set rsTmp = Nothing
        
        'For double top line and single bottom line for Subtotal
        TempString = "A" & RowStart & ":" & "T" & RowStart
        boldFontSize (TempString)
        applyDoubleTotalLine (TempString)
    
    objXLSheet.range("RowEnd").Select
        objXLSheet.ActiveCell.Formula = "= SUBTOTAL(101, B" & RowEnd & ":B" & recount + 6 & ")"

  2. #2
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 07
    Location
    India
    Posts
    2,156

    Re: Remove records with 0 values

    why dont u avoid 0 values when u open recordset by query?
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  3. #3
    Lively Member
    Join Date
    Jan 12
    Posts
    71

    Re: Remove records with 0 values

    Hi Seenu,

    I'll prefer to remove from the result set only but now sure how to do that? I please send me the sample for the same.

    Please fine below code used for result set

    Code:
        strSelectSQL = "SELECT " & _
            "[Banker], " & _
            "[Income YTD], [AnnRevenue],  " & _
            "[VRevenueTargetCY], [RevenuePriorFY],  " & _
            "[VAnn vs Budget], [VAnnu vs Prior FY Revenue],  " & _
            "[Income YTD], [Ann ARevenue],  " & _
            "[ARevenueTargetCY], [ARevenuePriorFY],  " & _
    	...
    	...
    	...
    	...
    	"[AnnuVRevenue] / [TotalAnnuRevenue] AS [Annu Actual V Ratio] " & _
            "FROM tbl_WConsol  " & _
            "INNER JOIN tbl_Bankers ON tbl_WConsol.[Banker] = tbl_Bankers.[BankerNm] " & _
            "WHERE [YearMonthWeek] = '" & txtReportingMonth & CStr(gsReportingWeekNo) & "'" & _
            "AND Team = '" & sTeamRegionName & "'"
    
             Set rsTmp = gsPnPDatabase.OpenRecordset(strSelectSQL)
    
        recount = rsTmp.RecordCount
        rsTmp.MoveFirst
        RowEnd = RowStart + recount
    
    
        For count = 1 To recount
            ColumnStart = 1
            objXLSheet.Cells(RowStart, ColumnStart) = rsTmp![Banker]
            ColumnStart = ColumnStart + 1
            objXLSheet.Cells(RowStart, ColumnStart) = rsTmp![RevenueYTD]
            ColumnStart = ColumnStart + 1
            objXLSheet.Cells(RowStart, ColumnStart) = rsTmp![AnnuRevenue]
            ColumnStart = ColumnStart + 1
            objXLSheet.Cells(RowStart, ColumnStart) = rsTmp![RevenueTCY]
            ColumnStart = ColumnStart + 1
            objXLSheet.Cells(RowStart, ColumnStart) = rsTmp![RevenuePFY]
            ColumnStart = ColumnStart + 1
            objXLSheet.Cells(RowStart, ColumnStart) = rsTmp![AnnuVsBud]
            ColumnStart = ColumnStart + 1
            objXLSheet.Cells(RowStart, ColumnStart) = rsTmp![AnnuVsPFYRev]
            ColumnStart = ColumnStart + 1
            ..............
            ..............
            ..............
            ..............
            ..............
    
            ColumnStart = ColumnStart + 1
            objXLSheet.Cells(RowStart, ColumnStart) = rsTmp![AnnuActRatio]
    
            If rsTmp.EOF Then Exit For
            RowStart = RowStart + 1
            rsTmp.MoveNext
        Next count
    
        rsTmp.Close
        Set rsTmp = Nothing

  4. #4
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 07
    Location
    India
    Posts
    2,156

    Re: Remove records with 0 values

    something like this
    Code:
    "Select * From Tablename Where Column1 <> 0"
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  5. #5
    PowerPoster
    Join Date
    Dec 04
    Posts
    18,524

    Re: Remove records with 0 values

    There are few records with 0 values.
    0 value in a specific field or all fields blank?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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