小编emb*_*end的帖子

Excel VBA宏:"For Each ... In ..."循环中的"Object required"

这是Excel 2013中的VBA宏.

我正在循环播放Sheet 1,Col B中的单元格.对于每个单元格,我想要取其值并在Sheet 2,Col A中搜索.如果找到,我想在Sheet 2,Col中取相应的值B并将其放在Sheet 1,Col E中的相应行中.

这些表:

Tagging                 Automatic Categories
B     E                 A     B
hat                     cake  Delicious cake.
cake
arm
Run Code Online (Sandbox Code Playgroud)

应该成为:

Tagging                 Automatic Categories
B     E                 A     B
hat                     cake  Delicious cake.
cake  Delicious cake.
arm
Run Code Online (Sandbox Code Playgroud)

码:

Sub AutoCategorize()
Dim c As Range
Dim searchRng As Range
For Each c In Sheets("Tagging").Range("B6:B500").Cells ' loop through cells to do the lookup based on
    If Not c.Value Is Nothing Then ' if there is something in the cell …
Run Code Online (Sandbox Code Playgroud)

excel vba excel-vba

5
推荐指数
1
解决办法
5360
查看次数

标签 统计

excel ×1

excel-vba ×1

vba ×1