Tuesday, January 31, 2012

Generating PDF from excel


Generating PDF from excel..

Sub CreatePDF()
   
    Dim wksSheet As Worksheet
    Dim blnFlag As Boolean
    Dim intI As Integer
    Dim intResult As Byte
   
    intI = 0
    intResult = Application.InputBox("Type 1 for Entire Workbook and Type 0 For Active Worksheets")
    If intResult = 0 Then
    Set wksSheet = ActiveSheet
            wksSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
                    ThisWorkbook.Path & "\" & wksSheet.Name, Quality:=xlQualityStandard, _
                    IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
                    False
            Exit Sub
    End If
    For Each wksSheet In ThisWorkbook.Worksheets
        If WorksheetFunction.CountA(wksSheet.Cells) <> 0 Then
            If wksSheet.Visible = xlSheetHidden Then
                wksSheet.Visible = xlSheetVisible
                blnFlag = True
            End If
            wksSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
                    ThisWorkbook.Path & "\" & wksSheet.Name, Quality:=xlQualityStandard, _
                    IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
                    False
                    intI = intI + 1
            If blnFlag = True Then
            wksSheet.Visible = xlSheetHidden
            blnFlag = False
            End If
        End If
    Next
    MsgBox intI & " Worksheet(s) has been Exported to PDF", vbInformation
   
End Sub

Tuesday, January 3, 2012

How to Calculate Date Difference :

Try this Function
if A1 is Project Start date and A2 is  Project End Data . You can calculate aging between them in Year,Month and date :
Use this in A3
=DatedDiff(A1,A2)



Function DatedDiff(dtStart As Date, dtEnd As Date) As String
   
    Dim ArrStart
    Dim ArrEnd
    Dim ArrResult
   
    ArrStart = Array(Year(dtStart), Month(dtStart), Day(dtStart))
    ArrEnd = Array(Year(dtEnd), Month(dtEnd), Day(dtEnd))
    ArrResult = Array(0, 0, 0)
    If ArrEnd(2) < ArrStart(2) Then
        ArrEnd(2) = ArrEnd(2) + Day(CDate(ArrEnd(1) & "-1-" & ArrEnd(0)) - 1)
        ArrEnd(1) = ArrEnd(1) - 1
    End If
    ArrResult(2) = ArrEnd(2) - ArrStart(2)
    If ArrEnd(1) < ArrStart(1) Then
        ArrEnd(1) = ArrEnd(1) + 12
        ArrEnd(0) = ArrEnd(0) - 1
    End If
    ArrResult(1) = ArrEnd(1) - ArrStart(1)
    ArrResult(0) = ArrEnd(0) - ArrStart(0)
    If dtEnd < dtStart Then
        DatedDiff = "StartDate>EndData=TRUE"
    Else
        DatedDiff = "Year= " & ArrResult(0) & " | Month= " & ArrResult(1) & " | Day= " & ArrResult(2)
    End If
    Erase ArrStart
    Erase ArrEnd
    Erase ArrResult
End Function

Monday, January 2, 2012

Filter On Only Number and Text

Using Custom filter to filter only Numeric Values in a list :


if only need to Filter on Text Values in List ..