+ Reply to Thread
Results 1 to 8 of 8

loop question

  1. #1
    choice
    Guest

    loop question

    i have range d2:d1000
    if d = "Changed" then
    take the value in B of the same row and put in A of the same row.
    if d does not = "Changed" then
    exit sub

    any help on how to write this as a loop would be greatly appreciated

    thanks in advance



  2. #2
    Jezebel
    Guest

    Re: loop question

    With Worksheet
    for i = 2 to 1000
    if .Cells(i,4) = "Changed" then
    .Cells(i,1) = .Cells(i,2)
    else
    exit for
    end if
    Next
    End with



    "choice" <[email protected]> wrote in message
    news:[email protected]...
    >i have range d2:d1000
    > if d = "Changed" then
    > take the value in B of the same row and put in A of the same row.
    > if d does not = "Changed" then
    > exit sub
    >
    > any help on how to write this as a loop would be greatly appreciated
    >
    > thanks in advance
    >
    >




  3. #3
    chijanzen
    Guest

    RE: loop question

    choice:
    Try it

    d = 2
    Do While Cells(d, 4) <> "Changed"
    Cells(d, 1) = Cells(d, 2)
    d = d + 1
    Loop

    --

    http://www.vba.com.tw/plog/


    "choice" wrote:

    > i have range d2:d1000
    > if d = "Changed" then
    > take the value in B of the same row and put in A of the same row.
    > if d does not = "Changed" then
    > exit sub
    >
    > any help on how to write this as a loop would be greatly appreciated
    >
    > thanks in advance
    >
    >


  4. #4
    Nigel
    Guest

    Re: loop question

    You need to use ActiveSheet or Worksheet("Sheet1") not With Worksheet

    Also you might need to declare variable i, using Dim i as Long if the Option
    Explicit is turned on (recommended) at top of module.

    This procedure runs while column D contains "Changed" if it does not then
    the procedure exits, if you want to check ALL values in rows 2 to 1000 then
    remove the Exit For statement.
    --
    Cheers
    Nigel



    "Jezebel" <[email protected]> wrote in message
    news:[email protected]...
    > With Worksheet
    > for i = 2 to 1000
    > if .Cells(i,4) = "Changed" then
    > .Cells(i,1) = .Cells(i,2)
    > else
    > exit for
    > end if
    > Next
    > End with
    >
    >
    >
    > "choice" <[email protected]> wrote in message
    > news:[email protected]...
    > >i have range d2:d1000
    > > if d = "Changed" then
    > > take the value in B of the same row and put in A of the same row.
    > > if d does not = "Changed" then
    > > exit sub
    > >
    > > any help on how to write this as a loop would be greatly appreciated
    > >
    > > thanks in advance
    > >
    > >

    >
    >




  5. #5
    Bob Phillips
    Guest

    Re: loop question

    You could do it with a formula

    A2: =IF(COUNTIF($D$2:D2,"Changed")=COUNTA($D$2:D2),B2,"")

    and copy down

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "choice" <[email protected]> wrote in message
    news:[email protected]...
    > i have range d2:d1000
    > if d = "Changed" then
    > take the value in B of the same row and put in A of the same row.
    > if d does not = "Changed" then
    > exit sub
    >
    > any help on how to write this as a loop would be greatly appreciated
    >
    > thanks in advance
    >
    >




  6. #6
    Jezebel
    Guest

    Re: loop question

    I don't *need* to do anything. The code is obviously schematic. If you
    really wanted to be pedantic you might point out that is needs to be within
    a Sub or Function, within a code module, and with some mechanism for calling
    it. Or was your pomposity exhausted by that point?


    "Nigel" <[email protected]> wrote in message
    news:[email protected]...
    > You need to use ActiveSheet or Worksheet("Sheet1") not With Worksheet
    >
    > Also you might need to declare variable i, using Dim i as Long if the
    > Option
    > Explicit is turned on (recommended) at top of module.
    >
    > This procedure runs while column D contains "Changed" if it does not then
    > the procedure exits, if you want to check ALL values in rows 2 to 1000
    > then
    > remove the Exit For statement.
    > --
    > Cheers
    > Nigel
    >
    >
    >
    > "Jezebel" <[email protected]> wrote in message
    > news:[email protected]...
    >> With Worksheet
    >> for i = 2 to 1000
    >> if .Cells(i,4) = "Changed" then
    >> .Cells(i,1) = .Cells(i,2)
    >> else
    >> exit for
    >> end if
    >> Next
    >> End with
    >>
    >>
    >>
    >> "choice" <[email protected]> wrote in message
    >> news:[email protected]...
    >> >i have range d2:d1000
    >> > if d = "Changed" then
    >> > take the value in B of the same row and put in A of the same row.
    >> > if d does not = "Changed" then
    >> > exit sub
    >> >
    >> > any help on how to write this as a loop would be greatly appreciated
    >> >
    >> > thanks in advance
    >> >
    >> >

    >>
    >>

    >
    >




  7. #7
    Norman Jones
    Guest

    Re: loop question

    Hi Jezebel,

    >I don't *need* to do anything. The code is obviously schematic. If you
    >really wanted to be pedantic you might point out that is needs to be within
    >a Sub or Function, within a code module, and with some mechanism for
    >calling it. Or was your pomposity exhausted by that point?


    The fact that the OP posed an elementary loop question might suggest that
    your interpretation of obvious is rather optimistic.


    At the risk of exposing myself to a possible charge of pomposity, I would
    suggest that you use pseudo code only if there is good reason to believe
    that this will be manifestly obvious to the intended recipient.
    Additionally, in order to preclude responses such as Nigel's or, worse,
    confusing the OP, it might be wise make an appropriate disclaimer at the
    head of schematic code.



    ---
    Regards,
    Norman



  8. #8
    Nigel
    Guest

    Re: loop question

    Ditto...... and the response was for the OP to expand Jezebels' proposal. If
    the code was truly pseudo in nature then it was mightily detailed in parts -
    in fact one line away from working properly. I hope the OP benefited from
    it.

    --
    Cheers
    Nigel



    "Norman Jones" <[email protected]> wrote in message
    news:[email protected]...
    > Hi Jezebel,
    >
    > >I don't *need* to do anything. The code is obviously schematic. If you
    > >really wanted to be pedantic you might point out that is needs to be

    within
    > >a Sub or Function, within a code module, and with some mechanism for
    > >calling it. Or was your pomposity exhausted by that point?

    >
    > The fact that the OP posed an elementary loop question might suggest that
    > your interpretation of obvious is rather optimistic.
    >
    >
    > At the risk of exposing myself to a possible charge of pomposity, I would
    > suggest that you use pseudo code only if there is good reason to believe
    > that this will be manifestly obvious to the intended recipient.
    > Additionally, in order to preclude responses such as Nigel's or, worse,
    > confusing the OP, it might be wise make an appropriate disclaimer at the
    > head of schematic code.
    >
    >
    >
    > ---
    > Regards,
    > Norman
    >
    >




+ 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