Results 1 to 5 of 5

Applying page break function conditionally on the basis of cell value using macro

Threaded View

  1. #1
    Registered User
    Join Date
    07-31-2010
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    3

    Talking Applying page break function conditionally on the basis of cell value using macro

    Hi gurus,
    Presently I need to develop a macro that can apply page break in excel 2002 on the basis of the values of a particular column in the excel

    example
    CURRENT EXCEL

    Print Output in 1st page

    Col1 Col2

    1 a
    0 b
    0 c
    1 d
    0 e
    1 f
    0 g
    0 h


    I need to apply page break before the last cell value of col1 when the cell value=1using the macro mentioned below.

    EXCEL REQUIRED AFTER APPLYING CONDITIONAL PAGE BREAK USING MACRO
    Print Output in 1st page

    Col1 Col2

    1 a
    0 b
    0 c
    1 d
    0 e

    Print Output in 2nd page
    Col1 Col2

    1 f
    0 g
    0 h


    MACRO DEVELOPED SO FAR
    ----------------------------------------------START------------------------------------------------
    sList = sList & sFile & vbTab & sNewFileName & vbCrLf
    objFSO.CopyFile sFile, sNewFileName
    
    'Revenue excel report formatting start 
    						spos=InStrRev(sNewFileName,"Revenue")
    						
    						csFile.WriteLine "Inside Revenue excel report formatting Spos"+" "+ Cstr(spos)
    								if(spos>0) then
    										set app = createobject("Excel.Application")
    										set objWorkbook = app.Workbooks.Open(sNewFileName)
                                                                    objWorkbook.Sheets("Revenue-1").Select
                                                                    objWorkbook.Sheets("Revenue-1").Name = "Revenue"
    											objWorkbook.worksheets(objWorkbook.ActiveSheet.Name).activate  
    										set excelsheet =  objWorkbook.worksheets(objWorkbook.ActiveSheet.Name)
    										csFile.WriteLine "set excelsheet width"
    											 excelsheet.activate 
    											 excelsheet.Columns("A:A").ColumnWidth = 0.08
    											 excelsheet.Columns("B:C").ColumnWidth = 0
    											With excelsheet.PageSetup
    														.PrintTitleRows = "$3:$5"
    														.CenterHeader = ""
    														.RightHeader = ""
    														.LeftHeader = ""
    														sfooter=InStrRev(sNewFileName,"DRCReports\")
    														'msgbox"-"+ Cstr(sfooter)
    														sfooter=sfooter+11
    														'msgbox Cstr(sfooter)
    														endxls=InStrRev(sNewFileName,".xls")
    														'msgbox Cstr(endxls)
    														.LeftFooter =  Mid(sNewFileName,sfooter,endxls-sfooter+4)
    														.CenterFooter = "&P & of & &N"
    														.Orientation = 2
    														.Zoom = 95
    														.LeftMargin =  app.Application.InchesToPoints(0.25)
    														.RightMargin = app.Application.InchesToPoints(0.25)
    														.TopMargin =  app.Application.InchesToPoints(0.75)
    														.BottomMargin =app.Application.InchesToPoints(.8)
    														.HeaderMargin = app.InchesToPoints(0)
    														.FooterMargin = app.InchesToPoints(0.25)
    														.PrintQuality = 600
    											End With
    
    											objWorkbook.Save
    											app.Quit 
    									 csFile.WriteLine "Revenue excel report formatting Done"
    								end if
    'Revenue excel report formatting END
    
    If err.Number <> 0 then
        csFile.WriteLine "ERROR:Copy Failed"
        csFile.WriteLine "Error Number " & CStr(Err.Number) & " " & Err.Description	
    
    
    else
        csFile.WriteLine "Copy Worked"
    end if
    
    	oxFile.delete
    	osFile.delete
    	If err.Number <> 0 then
    	    	csFile.WriteLine "Delete Failed"
    	    	csFile.WriteLine "Error Number " & CStr(Err.Number) & " " & Err.Description	
    	else
        		csFile.WriteLine "Files deleted : " & oxFile & " and " & osFile
    	end if
    
    
      
    Set currentFolder = Nothing
    Set objFSO = Nothing
    Set file = Nothing
    Set xmlDoc = Nothing
    Set WshShell = Nothing
    Set WshSysEnv = Nothing
    'objFSO.CopyFile sFile, sNewFileName
    csFile.WriteLine "End Date and Time: " & date() & " "& time()
    ----------------------------------------------END-------------------------------------------------------------


    Please help ASAP
    Thanks
    Last edited by pike; 07-31-2010 at 05:58 AM. Reason: code tags for newbie pm rules

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1