A programmer’s wish

A programmer is walking along a beach and finds a lamp. He rubs the lamp, and a genie appears. “My Lord, I’m at your service, I can grant you any wish, but only ONE.”

The programmer pulls out a map, points to it and says, “I’d want peace in the Middle East.”

The genie responds, “Gee, I don’t know. Those people have been fighting for millenia. I can do just about anything, but this is likely beyond my limits.”

The programmer then says, “Well, I am a MS programmer, and we have lots of users. Please make all our users satisfied with our software and let them ask for sensible changes….”

At which point the genie responds, “Um, let me see that map again PLEASE.”


Warning is nothing

A programmer is smoking a cigarette and blowing smoke rings into the air. His girlfriend becomes irritated with the smoke and says, “Can’t you see the warning on the cigarette pack? Smoking is hazardous to your health!”

To which the man replies, “Warning is nothing! A programmer doesn’t worry about warnings; we only worry about errors.”

IT support

Programming is like sex:
One mistake and you have to support your child for the rest of your life.

Both hands

In an elementary school, the teacher gives school work to the class in PC lab. Everybody typing except little John. The teacher asks him:
– John, why aren’t you typing?
– I’m exhausted because of sex.
– That should not be a problem, type with your other hand, you must be able to type with two hands by now.

Use Find method against Cells collection to detemine the last used Row, Column in Excel

Function lastUsedRow() As Long
On Error Resume Next
Dim lLastRow As Integer
lLastRow = Cells.Find(What:=”*”, after:=Range(“A1″), SearchOrder:=xlByRows, _
If lLastRow = 0 Then
lLastRow = 1
End If
lastUsedRow = lLastRow

End Function

Function lastUsedCol() As Long
On Error Resume Next
Dim lLastCol As Integer
lLastCol = Cells.Find(What:=”*”, after:=Range(“A1”), SearchOrder:=xlByColumns, _
If lLastCol = 0 Then
lLastCol = 1
End If
lastUsedCol = lLastCol

End Function

Prompt for a file name using VBA

Function prompt4FileName(Optional sFolder As String = vbNullString, Optional sDefaultName As String = "Untitled") As String
    Dim sMacScript As String
    Dim sFileName As String

    If sFolder = vbNullString Then 'Get user document folder
        sFolder = userDocumentFolder()
    End If
    If isMac Then
        sMacScript = "set sFile to (choose file name with prompt ""Name this file"" default name """ & _
        sDefaultName & vbLf & _
        """ default location the path to documents folder)" & vbLf & _
        "return sFile"
        sFileName = MacScript(sMacScript)
        sFileName = Application.GetSaveAsFilename(sDefaultName, "Excel Files,*.xls,Excel macro enable files,*.xlsm,All Files,*.*", , "Name this file", "Save as")    End If
    prompt4FileName = sFileName
End Function

Looking for a row using Find method against the Selection object

Function myFindRowPos(sText As Variant, oSheet As Worksheet, _
  Optional SearchDirection As XlSearchDirection = xlNext, _
  Optional SearchOrder As XlSearchOrder = xlByRows, _
  Optional sFindRange As String = "A1:A10000", _
  Optional LookAt As XlLookAt = xlWhole) As Long

  Dim lResult As Long, oRg As Range

  On Error GoTo errLabel

 Set oRg = Selection.Find(What:=sText, after:=ActiveCell, LookIn:=xlValues, LookAt:= _ LookAt, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _ False)   If Not oRg Is Nothing Then
     lResult = oRg.Row
     lResult = -1 'not found
        End IferrExit:
    myFindRowPos = lResult
    Set oRg = Nothing
    Exit Function
    lResult = -1
    Resume errExit
End Function