Today I am going to present a simple macro to simulate the Excel proper function.
Please note that every formula in the spreadsheet will be converted to value.
Sub Capitalization()
'######################################################################
'Author Paolo Succo
'Date 09 December 2011
'Proper Function VBA
'Please note that all formulas will be converted as values
'######################################################################
Dim LastColumn As Integer
Dim LastRow As String
Dim ColumnLetter As String
Dim ColumnRange As String
Dim Target As Range
Dim ClickOption As String
Dim WarningMsg As String
WarningMsg = "Please be aware that all data will be converted as values and texts will be formatted as requested." & vbNewLine & "Would you like to proceed anyway?"
ClickOption = MsgBox(WarningMsg, vbQuestion + vbYesNo, "Warning!!!")
If Answer = vbYes Then
'Find Column Number
If WorksheetFunction.CountA(Cells) > 0 Then
LastColumn = Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
End If
'Find Column Letter
If LastColumn > 26 Then
ColumnLetter = Chr(Int((LastColumn - 1) / 26) + 64) & Chr(((LastColumn - 1) Mod 26) + 65)
Else
ColumnLetter = Chr(LastColumn + 64)
End If
'Find Last Row
If WorksheetFunction.CountA(Cells) > 0 Then
LastRow = Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
End If
ColumnRange = ColumnLetter + LastRow
Range("A1:" & ColumnRange).Select
For Each Target In Selection
Target.Value = Application.WorksheetFunction.Proper(Target.Value)
Next
Else
End If
End Sub
No comments:
Post a Comment