We all use VBA macro to automate reports and for that we are very much dependent on Google. Google provides lot of information but at times it’s difficult to locate the right piece of information. This blog is created to share some useful VBA codes which can be used by professionals in their work. You will find ready to use codes and formulas to make your job easy.
Tuesday, May 12, 2015
Sunday, May 3, 2015
Multiple Selection in data validation
Private Sub Worksheet_Change(ByVal Target As Range)
Dim RngDV As Range
Dim OldVal As String
Dim NewVal As String
If Target.Count > 1 Then GoTo exitHandler
Select Case Target.Column
Case 5 'this Case line works for column B only
'Case 2, 5, 6 'this Case line works for multiple columns
If Cells(Target.Row, 4) = "In" Or Cells(Target.Row, 3) = "Not In" Then
On Error Resume Next
'check the cell for data validation
Set RngDV = Target.SpecialCells(xlCellTypeAllValidation)
On Error GoTo exitHandler
If RngDV Is Nothing Then GoTo exitHandler
If Intersect(Target, RngDV) Is Nothing Then
'do nothing
Else
Application.EnableEvents = False
NewVal = Target.Value
Application.Undo
OldVal = Target.Value
Target.Value = NewVal
If OldVal <> "" Then
If NewVal <> "" Then Target.Value = OldVal & ", " & NewVal
End If
End If
End If
End Select
exitHandler:
Application.EnableEvents = True
End Sub
Friday, April 3, 2015
Sunday, October 26, 2014
Finding Cells Filled with a Particular Color
Finding Cells Filled with a Particular Color
- Press Ctrl+F to display the Find tab of the Find and Replace dialog box. (See Figure 1.)
- Make sure there is nothing in the Find What box.
- Click Format. (You may need to click Options to see the Format button.) Excel displays the Find Format dialog box.
- Make sure the Patterns tab is displayed. (See Figure 2.)
- From the colors available, choose the color you want to find.
- Click OK to close the Find Format dialog box.
- Click Find All. The Find and Replace dialog box expands to show the addresses of all the cells formatted with the color you specified in step 5. (See Figure 3.)
- Click one of the cell addresses in the bottom of the dialog box. Excel selects the cell within the actual worksheet.
- Press Ctrl+A. All of the addresses within the dialog box are selected.
- Click Close. All the cells of the desired color are selected.



Sub SelectColoredCells() Dim rCell As Range Dim lColor As Long Dim rColored As Range 'Select the color by name (8 possible) 'vbBlack, vbBlue, vbGreen, vbCyan, 'vbRed, vbMagenta, vbYellow, vbWhite lColor = vbBlue 'If you prefer, you can use the RGB function 'to specify a color 'lColor = RGB(0, 0, 255) Set rColored = Nothing For Each rCell In Selection If rCell.Interior.Color = lColor Then If rColored Is Nothing Then Set rColored = rCell Else Set rColored = Union(rColored, rCell) End If End If Next If rColored Is Nothing Then MsgBox "No cells match the color" Else rColored.Select MsgBox "Selected cells match the color:" & _ vbCrLf & rColored.Address End If Set rCell = Nothing Set rColored = Nothing
End Sub
To Customize the Ribbon in Excel 2013
To Customize the Ribbon in Excel 2013
You can customize the Ribbon by creating your own tabs with whichever commands you want. Commands are always housed within a group, and you can create as many groups as you want in order to keep your tab organized. If you want, you can even add commands to any of the default tabs, as long as you create a custom group in the tab.
- Right-click the Ribbon and then select Customize the Ribbon... from the drop-down menu.
- The Excel Options dialog box will appear. Locate and select New Tab.
- Make sure the New Group is selected, select a command, then click Add. You can also drag commands directly into a group.
- When you are done adding commands, click OK. The commands will be added to the Ribbon.
If you don't see the command you want, click the Choose commands from: drop-down box and select All Commands.
