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

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,367
Office Version
  1. 365
Platform
  1. Windows
Andy-s

Can you post what you have so far?
Code:
If Range("A1").Value  = "A" Then
   Transfer
End If
 
Upvote 0

just_jon

Legend
Joined
Sep 3, 2002
Messages
10,473
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

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
68,031
Office Version
  1. 365
Platform
  1. Windows
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,195,618
Messages
6,010,730
Members
441,566
Latest member
spimcom

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
Top