我有一个带有句子的A栏。
Column a Column b Column c
Sentences Word 1 Word 2 1
Sentence 1
Sentence 2
在该特定列A中,我需要找到一组关键字,如
Column J Column K
Word 1.1 Word 2.1
Word 1.2 Word 2.2
Word 1.3 Word 2.3
Word 1.4 Word 2.4
...
如果列A中存在上述任何关键字,则应将其粘贴到同一行中的下一个可用单元格上。
Column a Column b Column c
Sentences Word 1 Word 2
Sentence 1 Word 1.1
Sentence 2 Word 2.4
Dim col As Range, cell As Object
Dim col1 As Range, cell1 As Object
Application.ScreenUpdating = False
Sheets("Keyword").Select
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Set col = Selection
Sheets("Data").Select
Range("B1").Select
Range(Selection, Selection.End(xlDown)).Select
Set col1 = Selection
For Each cell In col
Range("B1").Select
Range(Selection, Selection.End(xlDown)).Select
Range("B2").Select
Range(Selection, Selection.End(xlDown)).Select
Line1:
Selection.Find(What:="bone", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Select
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = cell
Cells.FindNext(After:=ActiveCell).Activate
GoTo Line1
我正在尝试上面的代码,如果运行此代码,我的excel就会被挂起。
我是宏观的初学者,请帮助我。
答案 0 :(得分:0)
Dim col As Range, cell As Range
Dim col1 As Range, cell1 As Range
Application.ScreenUpdating = False
Set col = Sheets("Keyword").Range("a1:" & Sheets("Keyword").Range("a1").end(xldown).addresslocal)
For Each cell In col
If instr(1,cell,"bone") <> 0 then
cell.offset(0,500).end(xltoleft) = "bone"
end if
Next cell
此代码将循环遍历A列中的所有连续单元格,如果找到“bone”,它将使该行中的下一个可用单元格等于“bone”。
您的代码似乎与您所说的试图完成的内容不一致。这应该让你开始。
答案 1 :(得分:0)
@Kyle cell.offset(0,500).end(xlleft)=“bone”
声明不起作用。我已经成功完成了以下代码。
For i = 1 To 50
If cell.Offset(0, i).Value = "" Then
cell.Offset(0, i).Value = tag
Exit For
End If
Next i
还有其他简短方法吗?