1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Macro1 Does not work, Macro2 works. Why??

Discussion in 'Business Applications' started by PincivMa, Aug 5, 2012.

Thread Status:
Not open for further replies.
Advertisement
  1. PincivMa

    PincivMa Thread Starter

    Joined:
    Mar 13, 2004
    Messages:
    378
    Hi there

    I have done 2 very simple macros, Macro1 and Macro2 (See attachment). Macro1 does not work but Macro2 does. Only one line of code is different between the 2 macros. I want Macro1 to work like Macro2 but I cannot figure out how to do it. This has me stumped.

    Mario
     

    Attached Files:

  2. Garf13LD

    Garf13LD

    Joined:
    Apr 17, 2012
    Messages:
    455
    isblank(a:b) not isblank(a.b)
     
  3. PincivMa

    PincivMa Thread Starter

    Joined:
    Mar 13, 2004
    Messages:
    378
    Hi Garf13LD

    Sorry about the mix up. I did have isblank(a:b) in my original macro and it did not work. I made an error when I redid the macro in the attachment. So the problem is not solved. Change the isblank(a.b) to isblank(a:b) in the attachment and you will see that it does not work.

    Mario
     
  4. Garf13LD

    Garf13LD

    Joined:
    Apr 17, 2012
    Messages:
    455
    Not sure what you want to do, but this should fix it.
    If Application.CountA(Range("A:B")) = 0 Then
     
  5. PincivMa

    PincivMa Thread Starter

    Joined:
    Mar 13, 2004
    Messages:
    378
    The macro still does not work. I do not want to do the whole range A and B. I only want to do from cell A1 to cell A4 but I do not want to use the cell address since the cell addresses will vary in my macro. So I have done the following.

    a = ActiveCell.Address (refers to Cell A1 in this case)
    b = ActiveCell.Address (refers to Cell A4 in this case)

    So if Cells A1 to A4 are all blank, then ........

    In otherwords if there is something in Cell A5 the macro should still work.

    Mario
     
  6. PincivMa

    PincivMa Thread Starter

    Joined:
    Mar 13, 2004
    Messages:
    378
    Hi Garf13LD

    Thanks for the code. But instead of "Application.CountA(Range("a:b") = 0" which did not work, I replaced it with "Application.CountA(Range(a, b)) = 0" which did work. I guess that 2 brains are better than one.

    Below is the correct code for those that are interested.


    Sub Macro1()

    Sheets("Sheet1").Select
    Range("A1").Select
    a = ActiveCell.Address
    Range("A4").Select
    b = ActiveCell.Address
    If Application.CountA(Range(a, b)) = 0 Then
    Range("B1").Select
    End If
    End Sub
     
  7. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1063943

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice