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

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
81,623
Office Version
  1. 365
Platform
  1. Windows
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

ExcelHobbit

New Member
Joined
Jan 8, 2020
Messages
23
Office Version
  1. 2010
Platform
  1. Windows
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

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
81,623
Office Version
  1. 365
Platform
  1. Windows
That suggest that there is nothing in column B below B37, is that the case?
 
Upvote 0

ExcelHobbit

New Member
Joined
Jan 8, 2020
Messages
23
Office Version
  1. 2010
Platform
  1. Windows
there is data in B37, so can't figure out why it isn't working
 
Upvote 0

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
81,623
Office Version
  1. 365
Platform
  1. Windows
Is there anything below B37?
 
Upvote 0

ExcelHobbit

New Member
Joined
Jan 8, 2020
Messages
23
Office Version
  1. 2010
Platform
  1. Windows
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

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
81,623
Office Version
  1. 365
Platform
  1. Windows
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,186,662
Messages
5,959,060
Members
438,396
Latest member
Louise Rodway

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
Top