excel vba高手请进,这代码错在哪里了?

2024-11-22 19:34:24
推荐回答(5个)
回答1:

Dim strsheetname1 As String '声明全局变量strsheetname1
Dim strsheetname2 As String '声明全局变量strsheetname2
Sub chapter13()
Dim Ilen As Integer
strsheetname1 = ActiveSheet.Name
Ilen = Len(strsheetname1)
Sheets.Add after:=Sheets(strsheetname1)
strsheetname2 = Left(strsheetname1, Ilen - 1) + "条"
ActiveSheet.Name = strsheetname2
chapter13_1
End Sub
Sub chapter13_1()
Dim i As Integer, Irow As Integer, Icol As Integer
Sheets(strsheetname1).Activate
Irow = Sheets(strsheetname1).[Al].CurrentRegion.Rows.Count
Icol = Sheets(strsheetname1).[Al].CurrentRegion.Columns.Count
Range(Cells(1, 1), Cells(Irow, Icol)).Copy
Sheets(strsheetname2).Select
ActiveSheet.Paste
Range("Al").Select
Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
For i = 2 To Irow - 2
Cells(i * 2, 1).Select
Selection.EntireRow.Insert
Next i
Range(Cells(2, 1), Cells(2, Icol)).Copy
For i = 2 To Irow - 2
Cells(i * 2, 1).Select
ActiveSheet.Paste
Next i
Application.CutCopyMode = False
End Sub

回答2:

Sheets(strsheetname1).Activate'提示说这里出问题了
改为Sheets("strsheetname1").Activate'提示说这里出问题了

回答3:

Sub chapter13_1()
Dim i As Integer, Irow As Integer, Icol As Integer
Sheets(strsheetname1

上面要调用的strsheetname1变量是多少呢??
程序到这里的时候不知道它应该是多少啊

回答4:

strsheetname1必须定义为全程变量!

回答5:

提示什么错误呢?