Excel VBA taking user input to check a cell across multiple sheets and save specific sheets for later use -
i'm new vba, , trying write program in excel allow me manually input row , column program. program should check specified cell in multiple sheets see if it's 1 or 0. if it's 0, need specific worksheet in saved , identified later in output box.
below have far. parts i'm unsure saving specified worksheet, , specifying cell used check input box (ie if cj.range(d h) vs cj.cell(dh) etc.).
option explicit sub trial1() dim hr single dim d single d = inputbox("please enter day study. monday = a, tuesday = b, wed = c, thurs = d, fri = e, sat = f, sun = g.") hr = inputbox("please enter hour study in military time.") if hr >= 7 or hr <= 22 exit loop call worksheet1() end sub sub worksheet1() dim availability() string dim c1 worksheet dim c2 worksheet dim c3 worksheet dim c4 worksheet dim c5 worksheet dim c6 worksheet dim c7 worksheet dim c8 worksheet dim c9 worksheet set c1 = activeworkbook.sheets("3043") set c2 = activeworkbook.sheets("2222") set c3 = activeworkbook.sheets("2205") set c4 = activeworkbook.sheets("3138") set c5 = activeworkbook.sheets("1011") set c6 = activeworkbook.sheets("1012") set c7 = activeworkbook.sheets("1016") set c8 = activeworkbook.sheets("1219") set c9 = activeworkbook.sheets("2245") j = 1 9 if cj.range(dhr) = 0 redim preserve availability(0 ubound(availability) + 1) string end if next j
possible alternative
'for = 1 n 'if worksheets(i).cells(h, d).value = 0 msgbox ("there room available in room sheet" & & ".") 'if worksheets(i).cells(h, d).value = 1 msgbox ("room") 'next
edit: clarified msgbox @ end: either no places available, or list of 'places' (which happens worksheet name).
here example of how spin through desired sheets , find ones have 0 in desired row/column. pass list calling subroutine, or deal found.
option explicit sub trial1() dim hr long dim d long d = inputbox("please enter day study. monday = 1, tuesday = 2, wed = 3, thurs = 4, fri = 5, sat = 6, sun = 7.") hr = inputbox("please enter hour study in military time.") if hr >= 7 or hr <= 22 exit loop call check_sheets(hr, d) end sub function check_sheets(lrow long, lcol long) dim availability() string dim integer dim ws worksheet dim iavail integer dim strmsg string ' note: included "'" delimiter in case combined numbers give false sheet name. const sheetnames = "'3043'2222'2205'3138'1011'1012'1016'1219'2245" each ws in thisworkbook.sheets ' find worksheets if instr(1, sheetnames, "'" & ws.name) > 0 ' sheet want? if ws.cells(lrow, lcol).value & "" = 0 ' cell = 0 (warning: make sure no null values else!) iavail = iavail + 1 ' count available redim preserve availability(iavail) availability(iavail) = ws.name ' save sheet name end if end if next ws ' list available sheets if iavail > 0 strmsg = "area 1, 2 , 3 saved in array" & vbcrlf & vbcrlf 'this part i'm unsure (thebanks) = 1 iavail debug.print "available: " & availability(i) strmsg = strmsg & availability(i) & vbcrlf next msgbox strmsg, vbokonly, "the following areas available" else msgbox "there no places available", vbokonly, "none available" end if end function
Comments
Post a Comment