请高手帮我转一下吧谢谢了excel里有好多工作表主要操作“总表”这个sheetSub优化表格()'先排序再合并单元格ActiveSheet.Name="总表"Range("a3:ai2000").Sortkey1:=Range("a1"),order1...
请高手帮我转一下吧 谢谢了
excel里有好多工作表 主要操作“总表”这个sheet
Sub 优化表格()
'先排序 再合并单元格
ActiveSheet.Name = "总表"
Range("a3:ai2000").Sort key1:=Range("a1"), order1:=xlAscending, Header:=xlGuess ' paixu
Dim i As Integer 'merge
Dim j As Integer
Dim n As Integer
Dim flag As Boolean
Dim flag1 As Boolean
i = 2
j = 3
n = Sheets("总表").UsedRange.rows.Count
For i = 4 To n
itext = Range("a" & i)
jtext = Range("a" & j)
While jtext = itext
flag = True
If i = n - 1 Then
Exit For
End If
i = i + 1
itext = Range("a" & i)
jtext = Range("a" & j)
Wend
If flag = True Then
i = i - 1
Application.DisplayAlerts = False
Range("a" & j & ":" & "a" & i).merge
Application.DisplayAlerts = True
End If
j = i + 1
i = i + 1
Next
End Sub
Private Function SheetExists(sname) As Boolean
'如果活动工作簿中存在表SNAME则返回真
Dim x As Object
On Error Resume Next
Set x = ActiveWorkbook.Sheets(sname)
If Err = 0 Then SheetExists = True
If Err <> 0 Then SheetExists = false
End Function
求解答
展开