+ Reply to Thread
Results 1 to 4 of 4

How do I skip a blank cell within macro?

  1. #1
    Registered User
    Join Date
    11-10-2004
    Posts
    23

    Unhappy How do I skip a blank cell within macro?

    I have the following for...next loop:

    Dim K as Variant
    K = 0
    For F = 1 To 250
    Range("B" & K).Select
    ActiveCell.FormulaR1C1 = "=IF(RC[-3]="""",0,IF(RC[1]="""",1,0))"
    K = K + 1
    Next F


    Basically, if Range("A" & F) was blank, I don't want the formula to be entered in column B. So, something like:

    IF Range("A" & F)="" Then K = K + 1; Next F ...or something similar. How do I do it?

    I'm fairly new to VBA programming, so bear with me!

    (BTW - please don't question the K variant, just go with it. It's part of a longer routine, but the K variant is relevant for the purpose of this example).

    Thanks.

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    IF Range("A" & F)="" then
    K = K + 1
    else
    ActiveCell.FormulaR1C1 = "=IF(RC[-3]="""",0,IF(RC[1]="""",1,0))"
    K = K + 1
    end if

  3. #3
    Registered User
    Join Date
    11-10-2004
    Posts
    23
    Thanks mudraker, that's worked a treat. Great stuff, thanks again!

  4. #4
    Trevor Shuttleworth
    Guest

    Re: How do I skip a blank cell within macro?

    Dim K as Variant
    K = 0
    For F = 1 To 250
    If Range("A" & F) <> "" Then
    Range("B" & F).FormulaR1C1 = "=IF(RC[-3]="""",0,IF(RC[1]="""",1,0))"
    End If
    K = K + 1
    Next F

    "DJ Dusty" <[email protected]> wrote in
    message news:[email protected]...
    >
    > I have the following for...next loop:
    >
    > -Dim K as Variant
    > K = 0
    > For F = 1 To 250
    > Range("B" & K).Select
    > ActiveCell.FormulaR1C1 = "=IF(RC[-3]="""",0,IF(RC[1]="""",1,0))"
    > K = K + 1
    > Next F-
    >
    > Basically, if *Range("A" & F)* was blank, I don't want the formula to
    > be entered in column B. So, something like:
    >
    > *IF Range("A" & F)="" Then K = K + 1; Next F* ...or something similar.
    > How do I do it?
    >
    > I'm fairly new to VBA programming, so bear with me!
    >
    > (BTW - please don't question the K variant, just go with it. It's part
    > of a longer routine, but the K variant is relevant for the purpose of
    > this example).
    >
    > Thanks.
    >
    >
    > --
    > DJ Dusty
    > ------------------------------------------------------------------------
    > DJ Dusty's Profile:
    > http://www.excelforum.com/member.php...o&userid=16335
    > View this thread: http://www.excelforum.com/showthread...hreadid=524597
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1