excel - Apply borders in a used cell Range VBA -


i trying apply a border around group of used cells dynamically. column range (b7:e7) number of rows vary, code needs dynamic. code below not achieving this:

sub borders()  application.screenupdating = false dim lnglstcol long, lnglstrow long  lnglstrow = activesheet.usedrange.rows.count lnglstcol = activesheet.usedrange.columns.count  each rngcell in range("b7:b" & lnglstrow)     if rngcell.value > ""         r = rngcell.row         c = rngcell.column         range(cells(r, c), cells(r, lnglstcol)).select             selection.borders                 .linestyle = xlcontinuous                 .weight = xlthin                 .colorindex = xlautomatic             end     end if next  application.screenupdating = true  end sub 

this code puts borders around non-empty cells beyond b7.

sub borders()      application.screenupdating = false      dim lnglstcol long, lnglstrow long      lnglstrow = activesheet.usedrange.rows.count     lnglstcol = activesheet.usedrange.columns.count      each rngcell in range(range("b7"), cells(lnglstrow, lnglstcol))         if rngcell.value > ""             rngcell.select 'select cells             selection.borders                 .linestyle = xlcontinuous                 .weight = xlthin                 .colorindex = xlautomatic             end         end if     next      application.screenupdating = true  end sub 

the code below puts borders around used range beyond b7:

sub bordersb()      application.screenupdating = false      dim lnglstcol long, lnglstrow long      lnglstrow = activesheet.usedrange.rows.count     lnglstcol = activesheet.usedrange.columns.count      range(range("b7"), cells(lnglstrow, 2)).borders(xledgeleft)         .linestyle = xlcontinuous         .weight = xlthin         .colorindex = xlautomatic     end      range(range("b7"), cells(7, lnglstcol)).borders(xledgetop)         .linestyle = xlcontinuous         .weight = xlthin         .colorindex = xlautomatic     end      range(cells(7, lnglstcol), cells(lnglstrow, lnglstcol)).borders(xledgeright)         .linestyle = xlcontinuous         .weight = xlthin         .colorindex = xlautomatic     end      range(cells(lnglstrow, 2), cells(lnglstrow, lnglstcol)).borders(xledgebottom)         .linestyle = xlcontinuous         .weight = xlthin         .colorindex = xlautomatic     end      application.screenupdating = true  end sub 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -