我有多個excel的基本數據,我需要根據列來整理數據,而排序後的數據具有唯一值和這些唯一值,我把它們放在數組中,基於獨特的價值觀,必須創建一個新的工作簿。錯誤saveas方法工作簿失敗在Excel中
我的問題:
- 當IM excuting宏觀有時它的顯示誤差
saveas method workbook class failed
- 我如何凍結列?
我的代碼:
sub marcel()
Dim sArray as string
Dim saArray as string
Dim Lastrow_Sub As Integer
Dim Lastrow_Aging As Integer
Dim Array_Sub As Variant
Dim Array_Sub_Aging As Variant
Dim rngFilter_Ws2 as range
Dim Sht6 as worksheet
Dim ColumnsToRemove2 as variant
Dim j2 as integer
Dim vItem2 as variant
Check_date = Format(Date, "yymm")
Sheets("q_Aging_base_data_incl_FDB").Columns("D:D").AdvancedFilter Action:=xlFilterCopy, _
CopyToRange:=.Range("AY1"), Unique:=True
Lastrow_Aging = .Cells(.Rows.Count, "AY").End(xlUp).Row
Array_Sub_Aging = Range("AY2:AY" & Lastrow_Aging)
saArray = Array_Sub_Aging(m, 1)
Sheets("BASE qry_Inventory Activation b").Columns("H:H").AdvancedFilter Action:=xlFilterCopy, _
CopyToRange:=.Range("AZ1"), Unique:=True
Lastrow_Sub = .Cells(.Rows.Count, "AZ").End(xlUp).Row
Array_Sub = Range("AZ2:AZ" & Lastrow_Sub)
sArray = Array_Sub(k, 1)
If sArray <> "APE" And saArray = "APE" Or sArray <> "XXUMA" And saArray = "XXUMA" Then
Dim NewBook_Sub_Aging As Workbook
Set NewBook_Sub_Aging = Workbooks.Add
With NewBook_Sub_Aging
.Title = saArray
NewBook_Sub_Aging.Worksheets("sheet1").Name = "Aging Inventory"
With rngFilter_Ws2
.AutoFilter Field:=4, Criteria1:=saArray, Operator:=xlFilterValues
.AutoFilter Field:=15, Criteria1:="reporting relevant Location", Operator:=xlFilterValues
.AutoFilter Field:=32, Criteria1:="<>(a) 0 - 360", Operator:=xlFilterValues
Set rngCopyAging_Sub = .SpecialCells(xlCellTypeVisible)
.AutoFilter ' Switch off AutoFilter
End With
rngCopyAging_Sub.Copy Destination:=NewBook_Sub_Aging.Worksheets("Aging Inventory").Cells(1, 1)
' Delete unwanted columns for subregions(APE and XXUMA) Aging
Set Sht6 = NewBook_Sub_Aging.Worksheets("Aging Inventory")
ColumnsToRemove2 = Array("Period", "AP_BU", "Subregion", "Strategic_BU", "Company_Code", "Company_name", "Plant_name", _
"Rep Location", "Storage_Location", "Storage_Location_name", "Date_last_goods_rec", "Stock_type", _
"Stock_type_name", "Kind_of_Material_name", "Supplier_name", "SummevonVEU_OIV1", "Days_since_production", _
"Remaining_shelf_life", "APO_Planner", "S_SCM_or_SVC")
For j2 = LBound(ColumnsToRemove2) To UBound(ColumnsToRemove2) Step 1
vItem6 = Application.Match(ColumnsToRemove2(j2), Sht6.Rows(1), 0)
Debug.Print vItem6
If IsNumeric(vItem6) Then
Sht6.Columns(vItem6).Delete
End If
Next j2
NewBook_Sub_Aging.Worksheets("Aging Inventory").Cells.EntireColumn.AutoFit
NewBook_Sub_Aging.Worksheets("Aging Inventory").Range("A1:P1").AutoFilter
NewBook_Sub_Aging.Worksheets("Aging Inventory").Range("A2:P2").Select
ActiveWindow.FreezePanes = True
.SaveAs Filename:="KPI" & " " & saArray & " " & Check_date & ".xlsx"
Application.DisplayAlerts = False
NewBook_Sub_Aging.Close
End With
End If
end sub
任何人都可以請幫我如何解決這個問題。
應該有'sArray'和'saArray'變量嗎?這一行是正確的:'sArray <>「APE」和saArray =「APE」或者sArray <>「XXUMA」並且saArray =「XXUMA」'或者它應該是'(sArray <>「APE」and saArray =「APE」 )或(sArray <>「XXUMA」和saArray =「XXUMA)」'? 'saArray'和'Check_date'的價值是什麼? 'saArray'是您在文件名中使用的值的數組嗎? –
我假設名字'check_date'是一個日期,可能包含正斜槓。文件名不能包含以下字符:\ /:*? 「| – LiamH
@ DarrenBartrup-Cook sArray and saArray contains string variables.ex APE,APED,APEA etc'sArray <>」APE「and saArray =」APE「or sArray <>」XXUMA「and saArray =」XXUMA「''是正確的行。「Check_date」包含當前月份。saArray不是它的字符串。文件名必須像這樣創建'KPI APE 1604.xlsx' –