Have you ever wanted to automatically number rows of data in Excel?
One way to do this is by using the Row function.
For example, type a heading such as ID into A1 then in A2 type the formula
=Row()-1
In this example suppose you want the numbers to be inserted automatically as you add new rows of data. This can be done by turning the data into an ExceI Table.
Click Home, Format as Table.
Select Table Tools Design then tick Total Row.
When you insert a new in the Total Row a new ID number will be inserted.
Note:The ID numbers will be updated if you sort, insert or delete rows of data.
On a recent Excel VBA Intermediate course everyone thought a macro for converting text to upper or proper case would be helpful. It’s a good one to put into your Personal Macro Workbook then assign to a button on your Quick Access Toolbar. Here’s how to do it:
1. Starting with a blank Workbook record a macro called ConvertCase in the Personal Macro Workbook. With Excel 2007 or Excel 2010 click View, Macros, Record Macro…
2. Press OK then straight away click Macros, Stop Recording.
3. Press Alt+F11 to view the VBA Editor and open the module and code window for the blank ConvertCase macro.
4. Now add the following code:
Sub ConvertCase()
‘Macro to start frmConvertCase
frmConvertCase.Show
End Sub
Sub Uppercase()
For Each rng In Selection
rng.Value = UCase(rng.Value)
Next rng
End Sub
Sub Propercase()
For Each rng In Selection
rng.Value = Application.WorksheetFunction.Proper(rng.Value)
Next rng
End Sub
5. Insert a User Form and name it frmConvertCase using the Properties window adding a caption ‘Convert Case’.
6. Add two Option buttons and two Command buttons to your form:
7. Name the controls Upper, Proper, OK and Cancel adding captions as shown below.
8. Double click the OK button and add the following code:
Private Sub OK_Click()
Dim rng As Range
If UPPER.Value = True Then
Call uppercase
ElseIf Proper.Value = True Then
Call propercase
Else
MsgBox “Please choose either upper or proper case”
End If
End Sub
9. Close the code window the double click the Cancel button adding the following code:
Private Sub Cancel_Click()
Unload frmConvertCase
End Sub
10. Finally close the VBA Editor and customise your Quick Access Toolbar.
Select More Commands, Choose commands from Macros and select your ConvertCase macro, Add, OK.
That’s it. You now have a permenant button to change case of any selected text!