Friday, August 29, 2014

Calculated Fields formulas used in SharePoint

Get Week of the year
=DATE(YEAR([Start Time]),MONTH([Start Time]),DAY([Start Time]))+0.5-WEEKDAY(DATE(YEAR([Start Time]),MONTH([Start Time]),DAY([Start Time])),2)+1

First day of the week for a given date:
=[Start Date]-WEEKDAY([Start Date])+1

Last day of the week for a given date:
=[End Date]+7-WEEKDAY([End Date])

First day of the month for a given date:
=DATEVALUE(“1/”&MONTH([Start Date])&”/”&YEAR([Start Date]))

Last day of the month for a given year (does not handle Feb 29). Result is in date format:
=DATEVALUE (CHOOSE(MONTH([End Date]),31,28,31,30,31,30,31,31,30,31,30,31) &”/” & MONTH([End Date])&”/”&YEAR([End Date]))
Day Name of the week : e.g Monday, Mon
=TEXT(WEEKDAY([Start Date]), “dddd”)
=TEXT(WEEKDAY([Start Date]), “ddd”)


The name of the month for a given date – numbered for sorting – e.g. 01. January:
=CHOOSE(MONTH([Date Created]),”01. January”, “02. February”, “03. March”, “04. April”, “05. May” , “06. June” , “07. July” , “08. August” , “09. September” , “10. October” , “11. November” , “12. December”)

Get Hours difference between two Date-Time :
=IF(NOT(ISBLANK([End Time])),([End Time]-[Start Time])*24,0)

Date Difference in days – Hours – Min format : e.g 4days 5hours 10min :
=YEAR(Today)-YEAR(Created)-IF(OR(MONTH(Today)
DAY(Today)
<=MONTH(Created),DAY(Today)
>=DAY(Created)),12,IF(AND(MONTH(Today)>MONTH(Created),DAY(Today)
“&Today-DATE(YEAR(Today),MONTH(Today)-IF(DAY(Today)

You can get Get more formulas from
http://office.microsoft.com/en-us/sharepointtechnology/HA011609471033.aspx

OR

http://msdn.microsoft.com/en-us/library/bb862071.aspx

Reference Page link:

Tuesday, August 5, 2014

Add a number of months to a date in Excel

Many of my friends have query about how to add / Subtract month in excel, Simple way of doing as below


=Date(Year(Start_Date) + add_year, Month(Start_Date) + add_month, Day(Start_Date) + add_day)

Thursday, July 3, 2014

Calculate Time in Excel

The simple way to calculate the time is sum the two time inputs, shown in below example:

Use Excel built-in function SUM to calculate. Use same as you calculate any number:
Below mention three cells A1, A2 and A3 formatted as time (hh:mm)

A1 = 04:15
A2 = 10:15
A3 has the formula: =SUM(A1:A2)

then A3 will have the correct values of 14:30.

This is only useful until total is below 24 hours, but if your total times are greater than 24 hours then things get different, it will round the calculation and start from beginning and you won't get correct answer.

e.g.: If you have :
A1 = 15:30 and A2 = 10:15 then A3 will have 01:45 instead of 25:45. I.e. any hours beyond 24 hours are dropped.

To retain the hours beyond 24, you have two alternatives:

1. If you want to convert the hours beyond 24 into days then use this cell format : dd:hh:mm. The total in the previous example will be 01:01:45 (1 day , 1 hour and 45 minutes)

2. If you want to keep the hours beyond 24 as is then use this cell format :[h]:mm. The total in the previous example will be 25:45.

In both cases the formula will remain as it is. Only the cell format differs.

Monday, June 16, 2014

How To Get Last Row in Excel VBA code

There are many programmatic way to find last row of data input, but the simplest is....

Dim LastRow 
LastRow = ws.Range("A1").End(xlDown).Row


Wednesday, May 21, 2014

Creating a file name as a Date stamp in a batch File


Source Code line
Dir>C:\myFile_%date:/=%.log

Output File Name
myFile_05212014.log

Friday, April 25, 2014

VBA code for Outlook - Reply Mail With Attachment

May times it happens that you want to Reply some mail with attachment but when you click reply, it removes the attachment from your mail, and you need to attach it manually. Following function will help you to reply mail with attachment.



'''''''''''''''''''''' Reply Module ''''''''''''''''''''''''''
Sub ReplyWithAttachments()  ' For Only single Reply
    Dim rpl As Outlook.MailItem
    Dim itm As Object
     
    Set itm = GetCurrentItem()
    If Not itm Is Nothing Then
        Set rpl = itm.Reply
        CopyAttachments itm, rpl
        rpl.Display
    End If
     
    Set rpl = Nothing
    Set itm = Nothing
End Sub
 
Sub ReplyALLWithAttachments()   ' For Reply ALL
    Dim rpl As Outlook.MailItem
    Dim itm As Object
     
    Set itm = GetCurrentItem()
    If Not itm Is Nothing Then
        Set rpl = itm.ReplyAll
        CopyAttachments itm, rpl
        rpl.Display
    End If
     
    Set rpl = Nothing
    Set itm = Nothing
End Sub

Sub ReplyOnly()  ' For Only Reply without Body message
    Dim rpl As Outlook.MailItem
    Dim itm As Object
    Set itm = GetCurrentItem()
    If Not itm Is Nothing Then
        Set rpl = itm.Reply
        rpl.subject = itm.subject
        rpl.Display
'        rpl.HTMLBody = rpl.HTMLBody

    SendKeys "^f"
    SendKeys "From:"
    SendKeys "{Enter}"
    SendKeys "{Esc}"
    SendKeys "{Home}"
    SendKeys "^+{End}"
    SendKeys "{Del}"
    SendKeys "^{Home}"
    
    End If
     
    Set rpl = Nothing
    Set itm = Nothing
End Sub

Function GetCurrentItem() As Object ' Will Create object for the current selected One mail
    Dim objApp As Outlook.Application
         
    Set objApp = Application
    On Error Resume Next
    Select Case TypeName(objApp.ActiveWindow)
        Case "Explorer"
            Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
        Case "Inspector"
            Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
    End Select
     
    Set objApp = Nothing
End Function
 
Sub CopyAttachments(objSourceItem, objTargetItem)   ' Coping the Attachment if exist.
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set fldTemp = fso.GetSpecialFolder(2) ' TemporaryFolder
   strPath = fldTemp.Path & "\"
   For Each objAtt In objSourceItem.Attachments
      strFile = strPath & objAtt.FileName
      objAtt.SaveAsFile strFile
      objTargetItem.Attachments.Add strFile, , , objAtt.DisplayName
      fso.DeleteFile strFile
   Next
 
   Set fldTemp = Nothing
   Set fso = Nothing
End Sub

'''''''''''''''''''''' End of Reply Module '''''''''''''''''''''''''''''''''''''''''''

VBA code for Outlook - Forward Mail Without Attachment

May times it happens that you want to forward some mail without attachment that you received with attachments, and you need to delete manually. Following function will help you to remove the attachment while you send mail to someone.

Sub ForwardMailWithoutAttachment() 
 On Error GoTo ErrorHandler
    Dim obj As Object
    Dim msg As Outlook.MailItem
    Dim newMsg As Outlook.MailItem
    Dim subject As String
    Dim myattachments As Outlook.Attachments
    
     ' check for multiple selections
    If ActiveExplorer.Selection.Count > 1 Then
        MsgBox "please select one email only"
        GoTo ProgramExit
    End If
     
    Set obj = ActiveExplorer.Selection.Item(1)
    If Not obj Is Nothing Then
        If TypeName(obj) = "MailItem" Then
            Set msg = obj
            Set newMsg = msg.Forward
            subject = obj.subject ' Copy the selected Mail Subject
            If Len(subject) = 0 Then
                GoTo ProgramExit
            End If
            
            '########### To Remove the Attachment ##############
            Set myattachments = newMsg.Attachments
            While myattachments.Count > 0
                       myattachments.Remove 1
            Wend
            '###########################################
            With newMsg
                .subject = subject
                .Display
            End With
        Else
            MsgBox "Cannot Run this Macro. Invalid Selection of Mail."
            GoTo ProgramExit
        End If
    End If
ProgramExit:
    Exit Sub
ErrorHandler:
    MsgBox Err.Number & " - " & Err.Description
    Resume ProgramExit

End Sub