Hi all,
I've encountered a problem in a report I am building where the VBA code applying borders to a range ending at the last row of data picks up many rows that are not 'truly blank' underneath the last data value.
Data is being populated with this formula which correctly returns "" if there is no match:
The data being fed into this is not a set number of rows, so I have applied this formula all the way down to row 5000 to ensure all data is captured.
This data is then copied into my report sheet using the following VBA code:
Then a border is applied to all data in the report with this VBA code. The intention is for it to only go down to the last data row (row 1176 with my current data) but it is actually going down to row 5004 which I assume is due to the index formula going down to row 5000:
Is there a way of ensuring that the borders only go down to the actual last data row?
Please let me know if you need any more info! Thanks in advance.
I've encountered a problem in a report I am building where the VBA code applying borders to a range ending at the last row of data picks up many rows that are not 'truly blank' underneath the last data value.
Data is being populated with this formula which correctly returns "" if there is no match:
Excel Formula:
=IFERROR(INDEX('ACP Data'!$A:$A,MATCH('Prepared Data'!$A2,'ACP Data'!$D:$D,0),1),"")
The data being fed into this is not a set number of rows, so I have applied this formula all the way down to row 5000 to ensure all data is captured.
This data is then copied into my report sheet using the following VBA code:
VBA Code:
Sheets("Report Data").Activate
Sheets("Report Data").Range("G2").Select
Range(Selection, Cells(Rows.Count, "G").End(xlUp)).Select
Selection.Copy
Sheets("Report").Activate
Sheets("Report").Range("C6").Select
ActiveCell.PasteSpecial Paste:=xlPasteValues, SkipBlanks:=True
Then a border is applied to all data in the report with this VBA code. The intention is for it to only go down to the last data row (row 1176 with my current data) but it is actually going down to row 5004 which I assume is due to the index formula going down to row 5000:
VBA Code:
Dim rngBottomRowStart As Range
Dim rngBottomRowEnd As Range
Dim rngDataUpperLeftCell As Range
Dim dataRange1 As Range
Set rngDataUpperLeftCell = Sheets("Report").Range("C5")
With rngDataUpperLeftCell
Set rngBottomRowStart = Sheets("Report").Cells(.End(xlDown).Row, .Column)
Set rngBottomRowEnd = Sheets("Report").Cells(rngBottomRowStart.Row, .End(xlToRight).Column)
End With
Set dataRange1 = Sheets("Report").Range(rngDataUpperLeftCell, rngBottomRowEnd)
With dataRange1.Borders
.LineStyle = xlContinuous
.ColorIndex = 1
.Weight = xlThin
End With
Is there a way of ensuring that the borders only go down to the actual last data row?
Please let me know if you need any more info! Thanks in advance.
Last edited by a moderator: