Loop and copy

seacrest

Active Member
Joined
Aug 15, 2002
Messages
301
I need a macro that will look down col D Range(D5:D45)
then if col E > 1
copy cell in col H
Paste in col D
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

lionelnz

Well-known Member
Joined
Apr 6, 2006
Messages
571
This is not clear. Do you mean you want to look down & see if cells in range(e5:E45) >1 copy cell in the same row of ColH to ColD?
 
Upvote 0

HarryS

Board Regular
Joined
May 2, 2008
Messages
212
sub tryThis
for rr = 5 to 45
if cells(rr,5)>1 then
cells(rr,4)=cells(rr,8)

next rr

end sub
 
Upvote 0

HarryS

Board Regular
Joined
May 2, 2008
Messages
212
<TABLE class=tborder id=post1589491 cellSpacing=0 cellPadding=6 width="100%" align=center border=0><TBODY><TR vAlign=top><TD class=alt1 id=td_post_1589491 style="BORDER-RIGHT: #ffffff 1px solid">Quote
I need a macro that will look down col D Range(D5:D45)
then if col E > 1
copy cell in col H
Paste in col D
<!-- / message --></TD></TR><TR><TD class=alt2 style="BORDER-RIGHT: #ffffff 1px solid; BORDER-TOP: #ffffff 0px solid; BORDER-LEFT: #ffffff 1px solid; BORDER-BOTTOM: #ffffff 1px solid">
user_online.gif


It should have been close.
Why are we looking down column D when the action is dependant on column E

</TD><TD class=alt1 style="BORDER-RIGHT: #ffffff 1px solid; BORDER-TOP: #ffffff 0px solid; BORDER-LEFT: #ffffff 0px solid; BORDER-BOTTOM: #ffffff 1px solid" align=right><!-- controls --></TD></TR></TBODY></TABLE>
 
Upvote 0

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
59,294
Office Version
  1. 365
Platform
  1. Windows
thanks but that diddn't work
It is usually more helpful if you describe in what way it didn't work. For example:
- error message (what message and/or what line of code)
- did nothing.
- did the wrong thing (What, where etc)

However, in this case, I think I can see the problem (and I suspect Harry didn't test his code before posting. ;) )

I'll work with his and make a couple of modifications. Try this:

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> tryThis()<br>    <SPAN style="color:#00007F">Dim</SPAN> rr <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN><br>    <br>    <SPAN style="color:#00007F">For</SPAN> rr = 5 <SPAN style="color:#00007F">To</SPAN> 45<br>        <SPAN style="color:#00007F">If</SPAN> Cells(rr, 5) > 1 <SPAN style="color:#00007F">Then</SPAN><br>            Cells(rr, 4) = Cells(rr, 8)<br>        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>    <SPAN style="color:#00007F">Next</SPAN> rr<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0

HarryS

Board Regular
Joined
May 2, 2008
Messages
212
Sorry about that was thinking of

if cells(rr,5)>1 then cells(rr,4)=cells(rr,8)

but stupidity struck me as a blockhead instead of a block if then end if
 
Upvote 0

Forum statistics

Threads
1,191,416
Messages
5,986,430
Members
440,029
Latest member
GabSSSH

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