excel - Trying to border the last row in VBA -


i trying select last row of table , use outside border around whole row until last column. here code

cells(application.rows.count, .columns.count).end(xlup).borderaround weight:=xlmedium 

before had

cells(application.rows.count, 1).end(xlup).borderaround weight:=xlmedium 

my second line of code bordered first cell. need outside border cells in row. have tried different things turning "range" error. these closest attempts. not error not need do.

thanks,

g

the problem in both of code attempts, selecting 1 cell. because using cells method, selecting single cell. need use cells in conjunction range object multicellular region.

assuming data starts in cell a1 on sheet1, here working code:

sub drawborder()      dim rngbottomrowstart       range     dim rngbottomrowend         range     dim rngdataupperleftcell    range      set rngdataupperleftcell = sheet1.range("a1")     rngdataupperleftcell         set rngbottomrowstart = sheet1.cells(.end(xldown).row, .column)         set rngbottomrowend = sheet1.cells(rngbottomrowstart.row, .end(xltoright).column)     end     sheet1.range(rngbottomrowstart, rngbottomrowend).borderaround weight:=xlmedium  end sub 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -