I am trying to create an Excel document for inventory management. I have already created a workbook where "daily sales" and "deliveries" are added and the sheet maintains an updated inventory, calculates income and net profit. This is all done in traditional Excel; However, this sheet has some problems, namely that I have to duplicate the sheet myself and change it for each month in the future (I am in a remote part of Africa where the people are not computer literate, and so the interface must be very simple).
I have recently discovered VBA Macros and have been writing them for this sheet. I have so far written a userform that has dropdown menus for month and year, and when you hit enter, the program duplicates a "master" document, autopopulates the dates across the top and saves the workbook as the input month and year. My questions are: How do I delete the last columns in the new workbook? In the Master sheet, there are 31 columns, but not all months have 31 days, so I want to delete the unnecessary columns, without deleting the "total" column that comes after. Once I have formatted the document, I would like to import the previous month's data from the last column of that inventory sheet.
This is the part of the code I am struggling with. I want to be able to delete the extra columns that are automatically filled in with the first couple of days of the next month, e.g., 28-Feb-16 then 1-Mar-16 then 2-Mar-16, where I can have the program find the March dates and delete their associated columns.
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
I hope this makes sense. I should also point out that I am rather new to VBA.