【发布时间】:2016-01-07 13:46:56
【问题描述】:
有什么想法为什么下面的代码不会在工作表中循环?
我正在尝试根据工作表名称在每个工作表中设置一列。它卡在活动工作表上,忽略了If ws.Name <> "Default"。这是作为一个模块构建的:
Sub LangID_update()
Dim wb As Workbook: Set wb = ThisWorkbook
Dim ws As Worksheet
Dim LastCol As Integer
Dim LastRow As Integer
Dim rng As Range
Application.ScreenUpdating = False
For Each ws In wb.Worksheets
If ws.Name <> "Default" Then
LastCol = ws.Cells(1, Columns.count).End(xlToLeft).Column
LastRow = ws.Cells(Rows.count, 1).End(xlUp).Row
Set rng = Range(Cells(2, LastCol + 1), Cells(LastRow, LastCol + 1))
With rng
For Each c In Range(Cells(2, LastCol + 1), Cells(LastRow, LastCol + 1))
If ws.Name = "ARGS" Then c.Value = "ESP"
If ws.Name = "AUTS" Then c.Value = "GR"
If ws.Name = "DEUS" Then c.Value = "GR"
Next c
End With
End If
Next
Application.ScreenUpdating = True
Set wb = Nothing
Set ws = Nothing
Set rng = Nothing
End Sub
【问题讨论】: