vba help - find "-" using intersect

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
976
Office Version
  1. 2010
Platform
  1. Windows
Hi Team,

I want to find string "-" charecter in specific Amounts columns. if found Macro should exit.

Below is sample code , which help in finding blank, Similar fashion how to find String charecter "-"


VBA Code:
Sub t()
Dim rng As Range
Set rng = Union(Columns(1), Columns(3), Columns(5), Columns(6), Columns(9), Columns(10), Columns(14), Columns(16))
Application.DisplayAlerts = False
On Error GoTo Skip:
    If Intersect(ActiveSheet.UsedRange, rng).SpecialCells(xlCellTypeBlanks).Count > 0 Then
        Beep
       MsgBox "Blanks"
    End If
Skip:
Err.Clear
Application.DisplayAlerts = True
End Sub


Thanks
mg
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Try:
VBA Code:
Sub a1159239a()

Dim rng As Range, c As Range
Set rng = Union(Columns(1), Columns(3), Columns(5), Columns(6), Columns(9), Columns(10), Columns(14), Columns(16))
Set c = rng.Find(What:="-", LookIn:=xlValues, lookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
    
    If Not c Is Nothing Then
       Beep
       MsgBox "-"
       Exit Sub
    End If

End Sub
 
Upvote 0
Hi Akuini,

Perfect ! This is awesome, millions of thanks for your help, (y) ?



Thanks
mg
 
Upvote 0
You're welcome, glad to help & thanks for the feedback. :)
 
Upvote 0

Forum statistics

Threads
1,223,249
Messages
6,171,031
Members
452,374
Latest member
keccles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top