我正在尝试为库存管理创建一个 Excel 文档。我已经创建了一个工作簿,其中添加了“每日销售额”和“交货”,并且该工作表维护了更新的库存,计算收入和净利润。这一切都在传统的 Excel 中完成;但是,这张表有一些问题,就是我必须自己复制这张表,以后每个月都要换一次(我在非洲偏远的地方,那里的人不懂电脑,所以界面一定很简单的)。
我最近发现了 VBA 宏,并一直在为这张表编写它们。到目前为止,我已经编写了一个用户表单,其中包含月份和年份的下拉菜单,当您按 Enter 键时,程序会复制一个“主”文档,自动填充顶部的日期并将工作簿保存为输入的月份和年份。我的问题是:如何删除新工作簿中的最后一列?在主表中,有 31 列,但并非所有月份都有 31 天,所以我想删除不必要的列,而不删除后面的“总计”列。格式化文档后,我想从该库存表的最后一列导入上个月的数据。
这是我正在努力解决的代码的一部分。我希望能够删除在下个月的前几天自动填充的额外列,例如,28-Feb-16 然后 1-Mar-16 然后 2-Mar-16,我可以在那里该程序查找三月日期并删除其关联的列。
Private Sub CmdEnter_Click()
'Duplicate Sheet
Sheets(Array("Daily Sales", "Total Inventory", "Deliveries",_
"Income Statement", "Profits")).Copy
'Fill Dates in Daily Sales
Sheets("Daily Sales").Activate
'Enter combo boxes into first cell
Range("B6").Select
ActiveCell = CDate("1-" & CmboMonth.Value & "-" &_
CmboYear.Value)
'Fill in Month Dates
Selection.AutoFill Destination:=Range("B6:AF6"), _
Type:=xlFillValues
'Auto-Size Columns
Cells.Select
Cells.EntireColumn.AutoFit
'
'Fill Dates in Total Inventory
Sheets("Total Inventory").Activate
'Enter combo boxes into first cell
Range("C5").Select
ActiveCell = CDate("1-" & CmboMonth.Value & "-" &_
CmboYear.Value)
'Fill in Month Dates
Selection.AutoFill Destination:=Range("C5:AG5"),_
Type:=xlFillValues
'Auto-Size Columns
Cells.Select
Cells.EntireColumn.AutoFit
'
'Fill Dates in Deliveries
Sheets("Deliveries").Activate
'Enter combo boxes into first cell
Range("B6").Select
ActiveCell = CDate("1-" & CmboMonth.Value & "-" &_
CmboYear.Value)
'Fill in Month Dates
Selection.AutoFill Destination:=Range("B6:AF6"),_
Type:=xlFillValues
'Auto-Size Columns
Cells.Select
Cells.EntireColumn.AutoFit
'
'Fill Dates in Income Statement
Sheets("Income Statement").Activate
'Enter combo boxes into first cell
Range("C4").Select
ActiveCell = CDate("1-" & CmboMonth.Value & "-" &_
CmboYear.Value)
'Fill in Month Dates
Selection.AutoFill Destination:=Range("C4:AG4"),_
Type:=xlFillValues
'Auto-Size Columns
Cells.Select
Cells.EntireColumn.AutoFit
'
'Fill Dates in Profits
Sheets("Profits").Activate
'Enter combo boxes into first cell
Range("E4").Select
ActiveCell = CDate("1-" & CmboMonth.Value & "-" &_
CmboYear.Value)
'Fill in Month Dates
Selection.AutoFill Destination:=Range("E4:AI4"),_
Type:=xlFillValues
'Auto-Size Columns
Cells.Select
Cells.EntireColumn.AutoFit
'Save As
ActiveWorkbook.SaveAs Filename:= _
"Macintosh HD:Users:meringue90:Desktop:" & CmboMonth.Value &_
CmboYear.Value , FileFormat:= _
xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
End Sub
我希望这是有道理的。我还应该指出,我对 VBA 相当陌生。