在EXCEL 中VBA 如何使用A列中的内容新建大量工作表
发布网友
发布时间:2022-05-01 04:28
我来回答
共3个回答
热心网友
时间:2022-06-24 10:47
我写了这段代码可行!对于重复的非法的都能自动忽略。
Sub CreatMySheets()
Dim m As Range, str As String, created As Boolean
On Error GoTo ErrorHandler
For Each m In Range([A1], Cells(Cells.SpecialCells(xlLastCell).Row(), 1))
str = m.Text
If str <> "" Then
If Not created Then
ActiveWorkbook.Sheets.Add After:=Worksheets(Worksheets.Count)
End If
created = False
ActiveSheet.Name = str
End If
Next m
On Error GoTo 0
Set m = Nothing
Application.DisplayAlerts = False
If created Then ActiveSheet.Delete
Application.DisplayAlerts = True
Exit Sub
ErrorHandler:
created = True
Resume Next
End Sub
有疑问,请Hi我或给我发百度消息
GoodLuck!
热心网友
时间:2022-06-24 10:47
假设名字在a2:a25,建一按钮,在代码窗口,将代码粘贴进去:
Private Sub CommandButton1_Click()
For Each cell In Range("a2:a25")
If cell <> "" And IsNumeric(cell) <> True Then
For Each sh In Worksheets
If sh.Name = cell Then GoTo line1
Next
Set newsh = Sheets.Add(After:=Sheets(Sheets.Count))
newsh.Name = cell
End If
line1:
Next
End Sub
热心网友
时间:2022-06-24 10:48
Sub AddSht()
Dim mySht As Worksheet
Dim AddSht As Worksheet
Dim i As Integer
Application.ScreenUpdating = False
Set mySht = ActiveSheet
For i = 1 To Range("A1").End(xlDown).Row
Set AddSht = Sheets.Add
AddSht.Name = mySht.Range("A" & i).Value
mySht.Select
Next i
Application.ScreenUpdating = True
End Sub