excel - How to use For/Next loops to print range based on check box status -
i having trouble putting code allows me @ status of check box , print specified range on worksheet if check box equals true , repeat loop given number of check boxes , ranges.
i utilizing 2 different - next loops try , accomplish task. below current code.
sub printgraphs() dim integer dim r integer = 16 18 if activesheet.oleobjects("checkbox" & i).object.value = true r = 1 3 worksheets("cut tables graphs").activate range("rangeset" & r).select activesheet.pagesetup.printarea = ("rangeset" & r) activesheet.pagesetup .papersize = xlpaperletter .orientation = xllandscape .zoom = false .fittopageswide = 1 .fittopagestall = 1 .leftmargin = application.inchestopoints(0.25) .rightmargin = application.inchestopoints(0.25) .topmargin = application.inchestopoints(0.25) .bottommargin = application.inchestopoints(0.25) .centerhorizontally = true .centervertically = true end application.printcommunication = true selection.printout copies:=1, collate:=true next r end if next end sub
i utilizing public constants on separate module define variable "rangeset". code on module follows.
public const rangeset1 = "b2:u51" public const rangeset2 = "w2:ap51" public const rangeset3 = "b53:u102"
i wanting code @ check boxes 16 through 18 , print corresponding range in value of check box equals true.
desired outcome:
if check box #16 equals true, print range "b2:u51", else next i
if check box #17 equals true, print range "w2:ap51", else next i
if check box #18 equals true, print range "b53:u102", else end loop
the error getting is: run-time error '1004': exception has been thrown target of invocation on line containing "range("rangeset" & r).select
any on finding solution problem appreciated. thank in advance.
i feel easiest approach create array values want record. once you've filled array, can print anywhere want using loop.
Comments
Post a Comment