If Then macro

andy-s

Board Regular
Joined
Mar 22, 2002
Messages
51
Hi,
I need some help writing a macro and would appreciate if anyone could give me a hint about what to do…

I’m already writing a macro called Copy. Inside this macro, I want to run another macro named Transfer only if cell A1 in Sheet1 contain the letter A. If the cell A1 doesn’t contain any letter at all, or a letter else than A, the macro Transfer should not be run, and the macro called Copy should carry on to the next step.

How should I write this?

Sincerely,
Andy-s
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Andy-s

Can you post what you have so far?
Code:
If Range("A1").Value  = "A" Then
   Transfer
End If
 
Upvote 0
Should the cell be just "A", or simply include "A" in its string?

Should it be limited to matching the case [ caps only ] ?
 
Upvote 0
Here is one way:
Code:
    If Not (Application.WorksheetFunction.Substitute(Range("D1"), "A", "") = Range("D1")) Then
        Transfer
    End If
This will check to see if "A" occurs anywhere where in that cell (D1 in my example).

Also, to avoid problems, you should avoid using reserved words as names of macros, i.e. don't name a macro Copy, since Copy is already a valid function/command in Excel and VBA. Name it something else like "MyCopy".
 
Upvote 0

Forum statistics

Threads
1,215,024
Messages
6,122,729
Members
449,093
Latest member
Mnur

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