|
楼主 |
发表于 2018-7-13 01:07
|
显示全部楼层
蓝桥玄霜 发表于 2018-7-8 15:34
Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True
Dim Myce ...
拆分成多表 宏,突然之间不能用了,我不太知道怎么回事,您帮我改的右击自定义菜单也不能用了,出现下图问题(我希望能运用到所以工作簿)
[img][/img]
[img][/img]
[img][/img]
Sub 拆分成多表()
'
' 拆分成多表 宏
'
Dim ggsht, strdateaddr, ggrg, myvalue1, myvalue2
myvalue1 = CStr(ThisWorkbook.Worksheets("Sheet1").Range("A1").Value)
myvalue2 = CStr(ThisWorkbook.Worksheets("Sheet1").Range("B1").Value)
Set ggsht = Sheets.Add
ggsht.Name = "结果"
strdateaddr = ThisWorkbook.Worksheets("Sheet1").UsedRange.Address
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=strdateaddr, Version:=xlPivotTableVersion14).CreatePivotTable _
TableDestination:=ggsht.Cells(1, 1), Tablename:=myvalue1, DefaultVersion:=xlPivotTableVersion14
ggsht.Cells(1, 1).Select
With ActiveSheet.PivotTables(myvalue1).PivotFields(myvalue1)
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables(myvalue1).AddDataField ActiveSheet.PivotTables(myvalue1).PivotFields(myvalue2), "计数项:" & myvalue2, xlCount
Set ggrg = ggsht.Range("B2")
Do Until ggrg.Value = ""
ggrg.ShowDetail = True
ActiveSheet.Name = ggrg.Offset(0, -1).Value
ActiveSheet.Columns.AutoFit
Set ggrg = ggrg.Offset(1, 0)
Loop
End Sub
Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True
Dim Mycell As CommandBar
On Error Resume Next
Application.CommandBars("Mycell").Delete
With Application.CommandBars("Mycell").Controls.Add(Type:=msoControlPopup, before:=1, temporary:=False)
.BeginGroup = True
.Caption = "VBA自制宏(丸子)"
With .Controls.Add(Type:=msoControlButton)
.Caption = "拆分成多表"
.FaceId = 9590
.OnAction = "拆分成多表"
End With
.ShowPopup
End With
End Sub |
|