本文介绍了如何根据条件从一张纸移动到另一张纸? Excel Vba的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过以下条件将名称和必填项从sheet1移至sheet2中的空列:个人代码.
如果代码匹配,则前两行(sheet1中的名称和必填名称)将sheet2中的空白字段更新为相同的个人代码,这可能吗?

手动不带比较和更新功能,如下所示:

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



随附文档. http://www.filehost.ro/3100176/test_xlsm/



Document attached.http://www.filehost.ro/3100176/test_xlsm/

推荐答案

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 ... then语句.



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


这篇关于如何根据条件从一张纸移动到另一张纸? Excel Vba的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 19:38