Create a border around a range of dynamic cells

riedyp

Board Regular
Joined
Feb 13, 2020
Messages
88
Office Version
  1. 365
Platform
  1. Windows
Hello,
I have a table dependent on another table that users will input information. I am trying to make my table dynamic, meaning that I want the border to move up and down with the displayed values when it is updated by a command button.
For example, from my picture I would like the border to be around the range of B23 to H(newRow). I do not want a border inside of that dynamic range. Any suggestions on how one might do that? Thank you.
VBA Code:
Private Sub UpdateButton_Click()
'newRow = ActiveSheet.Cells(1000, 3).End(xlUp).Row 'Goes to the last updated cell
'ActiveSheet.Cells(newRow, 3).Select
Dim lRow As Long, newRow As Long
lRow = ActiveSheet.Cells(Rows.Count, 3).End(xlUp).Row
For newRow = lRow To 1 Step -1
    If ActiveSheet.Cells(newRow, 3) <> 0 Then Exit For
Next
ActiveSheet.Cells(newRow, 3).Select
ActiveSheet.Range("B" & newRow).Resize(, 8).Borders(xlEdgeBottom).Weight = xlThin 'Creates bottom border
'ActiveSheet.Range(Cells(24,2),Cells(newRow,8).BorderAround , xlThin
'I want to create a border on the left,right and bottom of a range from B24 to H"newRow"
End Sub
 

Attachments

  • updated.PNG
    updated.PNG
    27.7 KB · Views: 117

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
I would use conditional formatting rule to put a bottom border on a cell if the current row is not blank and next row is blank.
 
Upvote 0
I wouldn't do it in the code. I would set up three conditional formatting rules on that sheet:

Applies to B24:I999 (change 999 to whatever is the maximum possible row you might use)
=AND($C24<>"",$C25="")
Format: Bottom border

Applies to B24:B999
=$C24<>""
Format: Left border

Applies to I24:I999
=$C24<>""
Format: Right border
 
Upvote 0
Thank you, I understand what you are saying now. I tried that but am having difficulties with it. I should note that the blank cells are actually filled with a formula
"='Project - Gantt Chart'!D23". But I did not think it would make a difference because the cells that they are referencing do not contain a value.
 
Upvote 0
What is in cell 'Project - Gantt Chart'!D23 ? Is it empty, or does it also have a formula?

Is there any way for you to share the file?
 
Upvote 0
D23 is an empty cell. I wasn't sure if i am allowed to upload actual documents to the forum, but here are 2 screenshots of the "Project Gantt Chart" sheet.
 

Attachments

  • d23.PNG
    d23.PNG
    45.3 KB · Views: 36
  • querstion.PNG
    querstion.PNG
    43.5 KB · Views: 36
Upvote 0
I should note that the blank cells are actually filled with a formula
"='Project - Gantt Chart'!D23". But I did not think it would make a difference because the cells that they are referencing do not contain a value.
That formula should result in 0 if D23 is an empty cell. Are you using formatting to suppress the display of a 0 cell?
 
Upvote 0
Okay and yes. I am trying to create a border around only the values that will appear and when I add values the border will expand around those and any border within the new expanded border will disappear.
 
Upvote 0
The image you showed in the first post is different than the subsequent one so I don't know which sheet is which or what you are really doing.

Here is an example of a sheet set up with the rules I described. I tried to make it look like your file although you didn't provide the formulas (the one formula you did provide--I'm not sure which direction it goes). Hopefully this will help you apply the same principle to your file.

 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top