Excel VBA: Repeatedly Add Outside Borders -


i need add outside borders ranges in multiple worksheets, have written following test code (which works):

sub testfun()      dim wb workbook     dim ws worksheet     set wb = workbooks("testbook.xlsm")      wb.worksheets("sheet1").select     range("b2:d10").select     addoutsideborders      wb.worksheets("sheet2").select     range("b2:d10").select     addoutsideborders      wb.worksheets("sheet3").select     range("b2:d10").select     addoutsideborders  end sub  sub addoutsideborders()     selection       .borders(xledgeleft).linestyle = xlcontinuous       .borders(xledgetop).linestyle = xlcontinuous       .borders(xledgebottom).linestyle = xlcontinuous       .borders(xledgeright).linestyle = xlcontinuous     end end sub 

however, real workbook contains many more sheets , need perform more complicated tasks. question is, how add borders without selecting range first? example want neat (it doesn't work):

sub testfun()      dim wb workbook     dim ws worksheet     set wb = workbooks("testbook.xlsm")      wb.worksheets("sheet1").range("b2:d10").addoutsideborders     wb.worksheets("sheet2").range("b2:d10").addoutsideborders     wb.worksheets("sheet3").range("b2:d10").addoutsideborders  end sub  sub addoutsideborders(rng range)     rng       .borders(xledgeleft).linestyle = xlcontinuous       .borders(xledgetop).linestyle = xlcontinuous       .borders(xledgebottom).linestyle = xlcontinuous       .borders(xledgeright).linestyle = xlcontinuous     end end sub 

more generally, how call function defined on range within sub?

the method attempted valid (and on trying avoid select), called procedure in incorrect way. instead, should called as:

call addoutsideborders(wb.worksheets("sheet1").range("b2:d10")) call addoutsideborders(wb.worksheets("sheet2").range("b2:d10")) call addoutsideborders(wb.worksheets("sheet3").range("b2:d10")) 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -