Results 1 to 8 of 8
  1. #1
    sbehera is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    May 2013
    Posts
    12

    Need help on a Macro for deleting columns in Excel output

    Hi,

    I am working on a MS access database macro which gives a output exported to an Excel.That is working fine.But there are too many columns in the exported output, out of which many columns are with all zero values.What I need is the delete the columns in the output excel where the sum of column is zero.I have tried something but was not able to do.Any help will be greatly appreciated.



    thanks.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,972
    If you don't want the columns, why include them in the export?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    sbehera is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    May 2013
    Posts
    12
    Hi June7 , Thanks for looking into my problem.Well the output Excel report is an Query result. There may be some values in some column as a result of one criteria where as the column may be zero on other criteria.hence, I cant ignore the columns itself before knowing that the entire column will be zero. So what I need is MS Access to look into it and delete the Zero values column. Hope it makes sense.
    Again thanks.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,972
    What have you tried? Every approach I can think of is complicated.

    Why is export to Excel necessary? Why is including the zero columns an issue?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    sbehera is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    May 2013
    Posts
    12
    Actually the output is generated querying a large table where the results needed to to be compared column by column.it will be giving around 50 to 60 columns where as the zero columns are needed to be deleted to make the comparison easy. As i have not much idea in Access VBA, I was trying to do some excel VBA run from MS Access. Well if it is so complicated then I will be doing it with an Excel Macro and that I can do. As this will add another step, I was looking for doing it from Access it self.
    Thanks again

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,972
    What is the comparison that needs to be done? Access has a FindUnmatched query wizard. Otherwise, VBA in Access could possibly do the comparison.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    sbehera is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    May 2013
    Posts
    12
    well I am not sure FindUnmatched will help me..I just want to delete the zero value columns in the excel output from VBA access.If that's complicated, I will take the report what now I am getting and use an Excel Macro to delete the columns.That's fine because what the current process is taking 3 to 4 hour, may be it will take 15 minutes, what could have been reduced to 5-7 minutes.

    nevertheless, thanks again.

  8. #8
    trevor40's Avatar
    trevor40 is offline Advanced db Manager
    Windows XP Access 2003
    Join Date
    Feb 2014
    Location
    Australia
    Posts
    402
    A snipit of code for you to check over, gives you an idea about how to control excel from access.
    P.S. A vba macro created using the record new macro in excel can be converted to use it in access, just adjust the referencing.

    Private Sub Command52_Click()
    Dim strPath As String
    Dim rst As DAO.Recordset
    Dim Excel_Application As Excel.Application
    Dim Excel_Workbook As Excel.Workbook
    Dim Current_Worksheet As Excel.Worksheet
    Dim Data_Range
    Dim Worksheet_Name
    Dim db As Database
    Dim rs As Recordset
    Dim headercell, firstcellref, nextname, FirstName, linecount, nextcellref, bb, CC, dd, rangestart, rangeend, Mt
    Dim aa As Integer
    gg = "C:\All Records for - " & Format(Date, "dd-mm-yy") & ".xls"
    t = Len(Dir(gg))
    If t = 0 Then
    GoTo keepgoing1
    Else
    t = MsgBox("File already exists, Delete file and continue ?.", vbYesNo, "")
    If t = vbYes Then
    Kill gg
    Else
    Exit Sub
    End If
    End If
    keepgoing1:
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "all records query", gg, True
    Set Excel_Workbook = GetObject(gg)
    Set Excel_Application = Excel_Workbook.Parent
    Excel_Application.WindowState = xlMinimized
    Excel_Application.Visible = True
    Excel_Workbook.Windows(1).Visible = True
    Excel_Workbook.Worksheets(1).Name = "All Records"
    Excel_Workbook.Worksheets("All Records").Tab.ColorIndex = 37
    Set Current_Worksheet = Excel_Workbook.Worksheets("All Records")
    Excel_Workbook.Worksheets("All Records").Select
    Current_Worksheet.Cells.Select
    With Selection
    Current_Worksheet.Cells.HorizontalAlignment = xlRight
    Current_Worksheet.Cells.Font.Name = "Times New Roman"
    End With
    Current_Worksheet.PageSetup.Orientation = xlLandscape
    Current_Worksheet.Range("A1:L1").HorizontalAlignme nt = xlCenter
    Current_Worksheet.Range("A1:L1").VerticalAlignment = xlCenter
    Current_Worksheet.Range("A1:L1").Font.Bold = True
    Current_Worksheet.Range("A1:L1").Font.Size = 14
    Current_Worksheet.Range("A1:L1").Interior.ColorInd ex = 14
    Current_Worksheet.Range("A1:L1").Font.ColorIndex = 2
    Current_Worksheet.Cells.SpecialCells(xlCellTypeLas tCell).Select
    Last_Cell = Current_Worksheet.Cells.SpecialCells(xlCellTypeLas tCell).Address
    rng1 = "A$1:L" & Mid(Last_Cell, 4, 3) ' Mid(Current_Worksheet.Cells.SpecialCells(xlCellTyp eLastCell).Address, 4, 3) - 1"
    Current_Worksheet.Range(rng1).Select
    With Selection
    Current_Worksheet.ListObjects.Add(xlSrcRange, , xlYes, xlYes).Name = "List1"
    End With

    Current_Worksheet.Range("C2").Select
    Excel_Application.ActiveWindow.FreezePanes = True
    Current_Worksheet.Range("A1:L1").Borders(xlEdgeTop ).LineStyle = xlContinuous
    Current_Worksheet.Range("A1:L1").Borders(xlEdgeTop ).Weight = xlThin
    Current_Worksheet.Range("A1:L1").Borders(xlEdgeTop ).ColorIndex = xlAutomatic
    Current_Worksheet.Range("A1:L1").Borders(xlEdgeBot tom).LineStyle = xlContinuous
    Current_Worksheet.Range("A1:L1").Borders(xlEdgeBot tom).Weight = xlThin
    Current_Worksheet.Range("A1:L1").Borders(xlEdgeBot tom).ColorIndex = xlAutomatic
    Current_Worksheet.Range("A1:L1").Borders(xlEdgeLef t).LineStyle = xlContinuous
    Current_Worksheet.Range("A1:L1").Borders(xlEdgeLef t).Weight = xlThin
    Current_Worksheet.Range("A1:L1").Borders(xlEdgeLef t).ColorIndex = xlAutomatic
    Current_Worksheet.Range("A1:L1").Borders(xlEdgeRig ht).LineStyle = xlContinuous
    Current_Worksheet.Range("A1:L1").Borders(xlEdgeRig ht).Weight = xlThin
    Current_Worksheet.Range("A1:L1").Borders(xlEdgeRig ht).ColorIndex = xlAutomatic
    Current_Worksheet.Range("A1:L1").Borders(xlInsideV ertical).LineStyle = xlContinuous
    Current_Worksheet.Range("A1:L1").Borders(xlInsideV ertical).Weight = xlThin
    Current_Worksheet.Range("A1:L1").Borders(xlInsideV ertical).ColorIndex = xlAutomatic
    Current_Worksheet.Range("1:1").RowHeight = 37.5
    Current_Worksheet.Range("A1:L1").WrapText = True
    Current_Worksheet.Range("D1").Value = "Normal Start Time"
    Current_Worksheet.Range("E1").Value = "Normal End Time"
    Current_Worksheet.Range("H1").Value = "Scan Time In"
    Current_Worksheet.Range("K1").Value = "Scan Time Out"
    Current_Worksheet.Range("A:A").ColumnWidth = 16
    Current_Worksheet.Range("B:B").ColumnWidth = 16
    Current_Worksheet.Range("C:C").ColumnWidth = 10.43
    Current_Worksheet.Range("D:d").ColumnWidth = 16.14
    Current_Worksheet.Range("E:E").ColumnWidth = 16.14
    Current_Worksheet.Range("F:F").ColumnWidth = 15.29
    Current_Worksheet.Range("G:G").ColumnWidth = 13.57
    Current_Worksheet.Range("H:H").ColumnWidth = 14
    Current_Worksheet.Range("I:I").ColumnWidth = 25
    Current_Worksheet.Range("J:J").ColumnWidth = 12.71
    Current_Worksheet.Range("K:K").ColumnWidth = 16
    Current_Worksheet.Range("L:L").ColumnWidth = 25
    rng1 = "A$2:L" & Mid(Last_Cell, 4, 3) ' Mid(Current_Worksheet.Cells.SpecialCells(xlCellTyp eLastCell).Address, 4, 3) - 1"
    Current_Worksheet.Range(rng1).Select
    Current_Worksheet.Range(rng1).Interior.ColorIndex = 34
    Current_Worksheet.Range("C2").Select
    Excel_Workbook.Save
    MsgBox "Output to Excel complete," & vbCrLf & "File saved to - C:\All Records.xls" & vbCrLf & "Use Alt + TAB to switch to Excel and view results", vbOKOnly, "Report"
    End Sub
    Last edited by trevor40; 03-31-2014 at 01:10 AM. Reason: can't get rid of the damm smiie in the middle of the text

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Group Text Box to output in columns and not rows
    By Fuzz_cozens in forum Reports
    Replies: 1
    Last Post: 02-28-2014, 10:30 AM
  2. Output format in SendObject Macro
    By nhkhurum in forum Macros
    Replies: 11
    Last Post: 12-21-2013, 02:09 PM
  3. Deleting rows deletes all columns in my report
    By Access_Novice in forum Reports
    Replies: 3
    Last Post: 09-19-2013, 06:15 PM
  4. Macro - Output to html using a template
    By thudson in forum Access
    Replies: 1
    Last Post: 04-05-2013, 12:15 AM
  5. Deleting empty columns from a table
    By kapil0712 in forum Programming
    Replies: 3
    Last Post: 05-17-2010, 12:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums