當前位置:成語大全網 - 新華字典 - vba遍歷壹列根據條件在另壹列插入值

vba遍歷壹列根據條件在另壹列插入值

是不是要這個

Sub?dh()

Dim?i?As?Integer,?r?As?Integer

r?=?Range("b65536").End(xlUp).Row

For?i?=?3?To?r

With?Cells(i,?2)

If?.Text?=?"經理室"?Then?Cells(i,?3)?=?1001

If?.Text?=?"生產車間"?Then?Cells(i,?3)?=?1002

If?.Text?=?"銷售車間"?Then?Cells(i,?3)?=?1003

If?.Text?=?"保衛科"?Then?Cells(i,?3)?=?1004

End?With

Next

End?SubSub?dd()

Dim?c?As?Range

For?Each?c?In?Range("b3:b"?&?Range("b65536").End(xlUp).Row)

Select?Case?c

Case?"經理室"

Cells(c.Row,?3)?=?1001

Case?"生產車間"

Cells(c.Row,?3)?=?1002

Case?"銷售車間"

Cells(c.Row,?3)?=?1003

Case?"保衛科"

Cells(c.Row,?3)?=?1004

End?Select

Next

End?Sub