Click here to Skip to main content
15,887,433 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to move the name and surename from sheet1 to empty column in sheet2 by a condition: personal code.
If code match, first two line (name and surename from sheet1) update empty fields in sheet2 right to the same personal code.Is this possible?

Manually without compare and update functions, look like this :
Range("D9").Select
    Sheets("Sheet2").Select
    Range("D5").Select
    Sheets("Sheet1").Select
    Range("B9:C9").Select
    Range("C9").Activate
    Selection.Copy
    Sheets("Sheet2").Select
    Range("A5:B5").Select
    ActiveSheet.Paste
    Sheets("Sheet1").Select


Document attached.http://www.filehost.ro/3100176/test_xlsm/
Posted
Comments
ZurdoDev 27-Feb-12 10:33am    
The easiest thing to do is record a macro doing what you want, or at least as much of what you want. Then go in and edit it adding in your logic.
Maciej Los 28-Feb-12 11:53am    
Can you clarify your question? I'm affraid to download your file, because my web browser locks the content of page. Show us your problem. Use a pseudo-code, for example:
Until Sheet1!A & rownumber <> ""
if Sheet1!A & rownumber = Sheet2!A & rownumber then
copy
else
do not copy
end if
Loop

1 solution

The simplest way is:

VB
Dim srcWsh as Worksheet
Dim dstWsh as Worksheet
Dim i as Integer


srcWsh = ThisWorkbook.Worksheets("Sheet")
dstWsh = ThisWorkbook.Worksheets("Sheet2")

i = 2
j = 5
Do while
    'copy range A:D from sheet 1 starting from row 2 into sheet2 row 5
    srcwsh.Range("A" & i & ":D" & i).Copy dstWsh.Range("A" & j)
    'add 1 to set next row number
    i = i + 1
    j = j + 1
Loop


If you whould like to set condition, you need to add if ... then statement inside a loop.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900