找到非静态[值]并在“值”旁边粘贴范围(F1:G1);“发现”;cell-excelvba
我有一个查询词列表,我正在提交给数据库(a列),以生成编码匹配列表(F-H列)。F列是原始搜索词(因此A列中的某个地方存在精确匹配),G列包含匹配项,H列包含匹配项的代码。我需要做的是获取F列中的查询词,并在A列中找到它的伙伴。然后我需要获取相应的匹配项及其代码,并将其粘贴到A列(B列和C列)中原始搜索词的旁边 我这里的问题是将信息粘贴到正确的单元格中,因为“复制到”和“粘贴自”位置每次都会更改—F-H列中的编码匹配列表并不包含A列中的所有术语 我一直在互联网上搜索,但我似乎不知道我到底需要修改什么才能让粘贴功能正常工作 我附上了我的电子表格的简化版本和我一直在使用的代码的注释版本的图像找到非静态[值]并在“值”旁边粘贴范围(F1:G1);“发现”;cell-excelvba,vba,excel,Vba,Excel,我有一个查询词列表,我正在提交给数据库(a列),以生成编码匹配列表(F-H列)。F列是原始搜索词(因此A列中的某个地方存在精确匹配),G列包含匹配项,H列包含匹配项的代码。我需要做的是获取F列中的查询词,并在A列中找到它的伙伴。然后我需要获取相应的匹配项及其代码,并将其粘贴到A列(B列和C列)中原始搜索词的旁边 我这里的问题是将信息粘贴到正确的单元格中,因为“复制到”和“粘贴自”位置每次都会更改—F-H列中的编码匹配列表并不包含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
提前非常感谢您阅读本文并帮助我
此vba使用工作表函数vlookup
Sub ahhn()
Dim ws As Worksheet
Dim cel As Range
Set ws = ActiveSheet
With ws
For Each cel In .Range(.Range("A1"), .Range("A1").End(xlDown))
cel.Offset(0, 1) = WorksheetFunction.IfError(Application.VLookup(cel, .Range("F:H"), 2, 0), "")
cel.Offset(0, 2) = WorksheetFunction.IfError(Application.VLookup(cel, .Range("F:H"), 3, 0), "")
Next
End With
End Sub
你不能在b和c中使用一个简单的vlookup公式吗?我认为vlookup(或索引/匹配)公式可以工作。你介意在最后贴一个它应该是什么样子的例子吗?我是VBA新手,所以我不确定vlookup是否有效。不过,我绝对可以调查@ahhn VLookup不是VBA方法-它是一个工作表函数。如果vlookup不能在VBA中使用,我不确定它是否有效。我在A列中有超过2500个条目,这就是为什么我在寻找一个宏来帮助我重新组织数据库的输出。这非常有效!非常感谢。你介意向我解释一下它在做什么吗?