唉。哥见你这么无助,就帮你一把。也算不上最好的办法,但是行得通,而且便于你理
解。
在你进行下面的操作之前,先把你的文件备份。要是以下操作失误,数据丢了,不要怪
我。
第一步:进入EXCEL的FILES->OPTIONS->Customize Ribbon. 在右边的main tabs里勾
上Developer.点OK完事。
第二步:点DEVELOPER菜单->Record Macro.在Shortcut Key里填个快捷键,比如q.点
OK
完事。
第三步:点DEVELOPER菜单->Stop Recording Macro.
第四步:按alt+f11.把以下代码拷贝到 ' Keyboard Shortcut: Ctrl+q那一行下面。不
要把End sub 给弄没了。完了关掉代码窗口,代码会自动保存。
第五步:回到Sheet1.将光标定位到第一行。按下你刚才设定好的快捷键,比如ctrl+q.
这个宏按一次快捷键只帮你转一条数据过去。
看看代码里的注释。自己触类旁通吧。
CurrentRow = ActiveCell.Row
ActiveWorkbook.Sheets("Sheet1").Cells(CurrentRow, 1).Select
' Suppose the key in in column A. Change 1 to 2 if it is in column B, 3
if C...
Key = ActiveWorkbook.Sheets("Sheet1").Cells(CurrentRow, 1)
' Suppose the variable to be pasted in sheet2 is in column C. Change 3
to 4 if it is in column D,...
VarToTransfer = ActiveWorkbook.Sheets("Sheet1").Cells(CurrentRow, 3)
' Search the first 100000 records in sheet 2. If you have more records
than this, change this number.
For i = 1 To 100000
' Suppose the key is stored in column A in sheet 2. Change 1 to 2
if
it is in column B, ...
If ActiveWorkbook.Sheets("Sheet2").Cells(i, 1) = Key Then
' If it matches the current key, paste the variable in column c.
ActiveWorkbook.Sheets("Sheet2").Cells(i, 3) = VarToTransfer
' Move to the next row in sheet 1.
ActiveWorkbook.Sheets("Sheet1").Cells(CurrentRow + 1, 1).Select
' In column j of sheet 1, show the progress.
' WARNING: column j will be overwritten. Change 10 to other
numbers if there are data in column j.
' Delete column j before each batch of operations.
ActiveWorkbook.Sheets("Sheet1").Cells(CurrentRow, 10) = "Done"
Exit For
End If
Next