我有一个查询词列表,我将其提交给数据库(列A)以生成列表编码匹配(列FH)。列F是原始搜索词(所以在列A中存在完全匹配),列G包含匹配,并且列H包含匹配的代码。我需要做的是在F列中查询单词并在列A中找到它的伙伴。然后我需要将相应的匹配和代码粘贴到列A中的原始搜索词旁边(在列B & C )。在“找到”单元格旁边找到非静态[值]和粘贴范围(F1:G1) - Excel VBA
我的问题在这里越来越因为拷贝到正确的单元格粘贴和粘贴位置的改变,每次的信息 - 编码的比赛中列FH不包含A列中所有项的列表
我一直在搜索互联网,我似乎无法弄清楚究竟我需要更改以允许粘贴功能工作。
我附上了我的电子表格的简化版本和我一直在使用的代码的注释版本的图像。
Sub FindMatch()
LastRow = Cells(Rows.Count, 6).End(xlUp).Row
For i = 1 To LastRow
FindMe = Cells(i, 6).Value
Set FoundinList = Cells.Find(What:=FindMe, After:=ActiveCell, LookAt:=xlWhole)
If Not FoundinList Is Nothing Then
FoundinList.Select
ActiveCell.Offset(0, 1).Select
'At this point the cell I want the information pasted into is selected. Yay!
'Example: I am trying to find "abnormal digits" (F1) in Column A and paste
'G1:H1 into the appropriate cells in Columns B & C (In this case B15:C15)
'At this point in the code my cursor is on cell B15 - which is where I need it.
Range(Cells(i, 7), Cells(i, 8)).Copy
'This selects the appropriate range (G1:H1 in my example).
ActiveCell.Paste
'This is the problem string. I've tried naming the "ActiveCell" before initiating the copy
'string (ActiveCell.Name = "PasteHere") and then pasting into the named cell
'(Cells("PasteHere").Paste), but that gives me an invalid procedure call or argument on:
'Cells("PasteHere").Paste I've also tried pasting into a range:Range(Cells(PasteHere, 2)
', Cells(PasteHere, 3)).Paste -AND- using the formula that is created when you a record a
'macro (Application.CutCopyMode = False) but both of those give me an application
'/object-defined error.
End If
Next i
End sub
非常感谢您提前阅读本文并帮助我。
你不能在b和c中使用简单的查找公式吗? –
我认为一个vlookup(或索引/匹配)公式将起作用。你介意发布一个最终应该是什么样子的例子吗? – BruceWayne
我是VBA新手,所以我不确定vlookup是否可以工作。不过我绝对可以看看! – ahhn