Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 84
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default 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" wrote in message
...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 139
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default 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" wrote in message
...
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" wrote in message
...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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" wrote in message
...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default 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" wrote in message
...
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" wrote in message
...
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" wrote in message
...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default 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" wrote in message
...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
loop question dabith Excel Programming 6 June 13th 04 05:28 PM
One more loop question Patti[_5_] Excel Programming 11 June 6th 04 07:14 AM
another loop question Patti[_5_] Excel Programming 5 May 31st 04 07:43 AM
For loop question luvgreen[_3_] Excel Programming 1 February 20th 04 03:30 PM


All times are GMT +1. The time now is 01:56 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"