IF stmts to make code more user friendly

keith05281967

Board Regular
Joined
May 6, 2011
Messages
68
Greetings VBA Guru's,

I have 2 questions:

1. I recorded a macro to select column A, find and delete any duplicates found. Here is the code:

Columns("A:A").Select
ActiveSheet.Range("$A$1:$A$37").RemoveDuplicates Columns:=1, Header:=xlYes

I need the code to tell the user if no duplicates were found or if found, give the option to proceed with deleting or not. I'm sure this is an If stmt, but I don't know how to word it.


2. Somewhat similar to the 1st, I have some code that locates a column header. The code is listed below:

On Error GoTo Err1:
Cells.Find(What:="sale_date", after:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate

The problem i'm having is that if the column isn't found I get an error. I tried to solve that with the "On Error GoTo Err1:" sometimes it works and sometimes it doesn't. I'd rather have some kind of if stmt if not found then.....something that informs the user column "sale_date" isn't found, moving on.


thanks so much. I'm using excel 07.
Also can you please use code examples with explanations?

thanks in advance for your help,
Keith
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
The second one is easier to deal with

Code:
Dim Found As Range
Set Found = Cells.Find(What:="sale_date", after:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False)
If Found Is Nothing Then
    MsgBox "Not found", vbExclamation
Else
    Found.Select
End If
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,798
Members
452,943
Latest member
Newbie4296

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