vba - Excel Macro Sometimes Breaks? -


i've made macro duplicate excel spreadsheet when run once won't run again?

sub add_week()     'copy worksheet     dim test worksheet     sheets(1).copy after:=sheets(sheets.count)     set test = activesheet      'extend date     jamesdata = range("d2")     firstdate = datevalue(jamesdata)     seconddate = dateadd("w", 7, firstdate)     range("d2").select     activecell.formular1c1 = seconddate      'change sheet name     newname = range("d2").text     test.name = newname  end sub 

try code.

sub add_week()      dim newdate string      'copy last sheet     sheets(sheets.count).copy after:=sheets(sheets.count)      'extend date     newdate = dateadd("w", 7, datevalue(range("d2")))      'the main problem here, because sheet name can't accept "/, \ , single quote"     'return value "dateadd" method include slash default.     'so, change "dd-mmm-yy" format. if need others, modify format.     'but need valid sheet name.      'change data format desire format (8-jul-15)     newdate = format(newdate, "dd-mmm-yy")      'set date value     range("d2") = newdate      'change sheet name     activesheet.name = newdate  end sub 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -