我有一列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就会挂断。
我是宏的初学者,请帮帮我。
@Kyle cell.offset(0500).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
还有其他简短的方法吗?
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中的所有相邻单元格,如果找到"骨骼",则会使行中的下一个可用单元格等于"骨骼"。
您的代码似乎与您所说的要实现的目标不一致。这应该会让你开始。