Formatting to last row

ExcelHobbit

New Member
Joined
Jan 8, 2020
Messages
23
Office Version
  1. 2010
Platform
  1. Windows
I want to highlight cell b37 and until the last row (which might change) in order to format that range of data

this is what i have so far, whereby i have declared at the very start of the code the following:
Dim Lastrow as Long

originally i had it as range("B37:B150").Select, but i had to change this as the last row will change


VBA Code:
Range("B37:B & Rows.Count").Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
        .Weight = xlMedium
    End With
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
How about
VBA Code:
Sub ExcelHobbit()
   With Range("B37", Range("B" & Rows.Count).End(xlUp))
      .borders(xlDiagonalDown).LineStyle = xlNone
      .borders(xlDiagonalUp).LineStyle = xlNone
      With .borders(xlEdgeLeft)
          .LineStyle = xlContinuous
          .ColorIndex = xlAutomatic
          .TintAndShade = 0
          .Weight = xlMedium
      End With
   End With
End Sub
 
Upvote 0
thanks for responding. when i put that code in, it seems to only do cell B37, and not highlight all cells below it up until the last row...
 
Upvote 0
That suggest that there is nothing in column B below B37, is that the case?
 
Upvote 0
Is there anything below B37?
 
Upvote 0
yes there is. So i want B37 highlighted and down until the last cell of data, perhaps using until the last row of data found in column A
 
Upvote 0
Ok, try
VBA Code:
Sub ExcelHobbit()
   With Range("B37:B" & Range("A" & Rows.Count).End(xlUp).Row)
      .borders(xlDiagonalDown).LineStyle = xlNone
      .borders(xlDiagonalUp).LineStyle = xlNone
      With .borders(xlEdgeLeft)
          .LineStyle = xlContinuous
          .ColorIndex = xlAutomatic
          .TintAndShade = 0
          .Weight = xlMedium
      End With
   End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,190
Members
452,616
Latest member
intern444

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