0

## vba巢狀if問題

``````Sub 批次新增工作表()
'先把現存sheet弄成一個array
Dim shtName As String
For Each sht In Sheets
shtName = shtName & "/" & sht.Name
Next
shtName = Mid(shtName, 2)
shtArray = Split(shtName, "/")

'用迴圈設定一個範圍
For i = 2 To 79
x = Sheets("總表").Cells(i, "C")
'先判斷sheet是否存在,沒有再新增
a = Application.Match(x, shtArray, 0)
If IsError(a) Then
If Cells(i, "C").Font.FontStyle = "標準" Then
If x <> "" Then
Sheets("Blank").Copy Before:=Sheets("Blank")
ActiveSheet.Name = x
End If
End If
End If
Next i
End Sub
``````

### 1 個回答

0
paicheng0111
iT邦高手 1 級 ‧ 2019-11-05 18:09:59

``````Sub 批次新增工作表()
'先把現存sheet弄成一個array
Dim shtName As String, c As Range, rng As Range
For Each sht In Sheets
shtName = shtName & "/" & sht.Name
Next
shtName = Mid(shtName, 2)
shtArray = Split(shtName, "/")

'用迴圈設定一個範圍
Set rng = Range(Sheets("總表").Cells(2, "C"), Sheets("總表").Cells(79,"C"))
For Each c in rng
'先判斷sheet是否存在,沒有再新增
a = Application.Match(c.Value, shtArray, 0)
If IsError(a) Then
If c.value <> "" And not c.font.Italic Then
Sheets("Blank").Copy Before:=Sheets("Blank")
ActiveSheet.Name = c.value
End If
End If
Next c
End Sub
``````
vicky7933 iT邦新手 5 級 ‧ 2019-11-05 21:18:18 檢舉