excel - Delete Columns Using Date Function -


i apologize if have posted question incorrectly, still getting used stackexchange network.

i have created user-form duplicate template workbook, fill in dates of selected month , year, , delete columns because template workbook has 31 pre-formatted columns.

the problem having when click on "enter" button in user-form, workbook duplicates , saves, , puts dates across top, but, not execute "delete" line under "duplicate sheet". each sheet in workbook (daily sales, total inventory, deliveries, income statement, profits) when puts in dates across top, supposed delete columns greater "days" , less 31 columns after first date of month.

option explicit private sub userform_initialize() initializemonthscombo initializeyearscombo end sub private sub initializemonthscombo() dim months() string months =    split("january,february,march,april,may,june,july,august,_ september,october,november,december", ",")  dim integer = lbound(months) ubound(months)     me.cmbomonth.additem months(i) next end sub private sub initializeyearscombo()  const startyear integer = 2015 const endyear integer = 2035  dim integer = startyear endyear     me.cmboyear.additem next end sub private sub cmdenter_click() dim days integer dim startdate date      startdate = cdate("1-" & cmbomonth.value & "-" & cmboyear.value)     days = (datediff("d", startdate, dateadd("m", 1, startdate))) - 1  'duplicate sheet sheets(array("daily sales", "total inventory", "deliveries", "income    statement", "profits")).copy           'daily sales         dim dailysales worksheet         set dailysales = worksheets("daily sales")          populate dailysales, dailysales.range("b6"),            dailysales.range(dailysales.cells(6, 2), dailysales.cells(6, 2 +              days))         range(cells(1, 3 + days), cells(1, 32)).entirecolumn.delete          'total inventory         dim totalinventory worksheet         set totalinventory = worksheets("total inventory")          populate totalinventory, totalinventory.range("c5"),           totalinventory.range(totalinventory.cells(5, 3),           totalinventory.cells(5, 3 + days))         populate totalinventory, totalinventory.range("c5"),           totalinventory.range(totalinventory.cells(5, 3),           totalinventory.cells(5, 2))         range(cells(1, 4 + days), cells(1, 33)).entirecolumn.delete          'deliveries         dim deliveries worksheet         set deliveries = worksheets("deliveries")          populate deliveries, deliveries.range("b6"),          deliveries.range(deliveries.cells(6, 2), deliveries.cells(6, 2 +                days))         range(cells(1, 3 + days), cells(1, 32)).entirecolumn.delete          'income statement         dim incomestatement worksheet         set incomestatement = worksheets("income statement")          populate incomestatement, incomestatement.range("c4"),              incomestatement.range(incomestatement.cells(4, 3),              incomestatement.cells(4, 3 + days))         range(cells(1, 4 + days), cells(1, 33)).entirecolumn.delete          'profits         dim profits worksheet         set profits = worksheets("profits")          populate profits, profits.range("e4"),             profits.range(profits.cells(4, 5), profits.cells(4, 5 + days))         range(cells(1, 6 + days), cells(1, 35)).entirecolumn.delete     end sub public sub populate(destsheet worksheet, first range, dest   range)     dim startdate date     startdate = cdate("1-" & cmbomonth.value & "-" & cmboyear.value)      first.value = startdate     first.autofill destination:=dest, type:=xlfillvalues      destsheet.cells.entirecolumn.autofit  'close userform unload me  end sub  private sub cmdcancel_click() 'close userform unload me end sub 

i solved problem! issue when went delete columns on each sheet, not changing reference sheet, , deleting column on active sheet, first sheet "daily sales", 5 times, instead of changing sheets. needed clarify range sheet.

range(cells(1, 3 + days), cells(1, 32)).entirecolumn.delete 

becomes:

range(deliveries.cells(1,3+days), deliveries.cells(1,32))_ .entirecolumn.delete 

which think r3uk trying tell me, didn't understand. thank r3uk!


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -