How do you assign a range for formatting when combined with resizing?

vbaNumpty

Board Regular
Joined
Apr 20, 2021
Messages
171
Office Version
  1. 365
Platform
  1. Windows
Trying to resize a range and apply borders around it, but I get application/object defined error.

What is the proper way to code the following?

VBA Code:
        With Range(addMe.Resize(0, 17)).Borders
            .LineStyle = xlContinuous
            .Weight = xlThin
        End With

addme is a range that is assigned
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Just use
VBA Code:
With addMe.Resize(0, 17).Borders
 
Upvote 0
Do you want to change the number of rows being formatted.
 
Upvote 0
Do you want to change the number of rows being formatted.
Yes, in some instances the formatting is more than one row. It is based on the number of line items tied to the customer.


The addme is set to one cell
VBA Code:
Set addMe = dshBoard.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)

that is then resized and merged

VBA Code:
addMe.Resize(x - 1).Merge

the resize is dependent on how many line items are in the order.

I figured when you select a merged section in excel and move to the right with shift it selects all the rows that make up the initial merged selection.

I'm guessing vba doesn't like that and I have to specify the number of rows somehow?
 
Upvote 0
Do you want to change the number of rows being formatted.
I fixed the object error by assigning the same row variable as before (x-1)

but now I get 438 error, Object doesn't support this property or method for :
VBA Code:
.LineStyle = xlContinuous

I am just trying to apply the all borders formatting.
 
Upvote 0
In that case I'm out. Merged cells are an abomination & should be avoided like the plague.
Figured it out, screwed up syntax forgetting the .borders argument after I fixed the row argument error.

Thanks for your help! Your assistance unlocked the key for me to figure out how to work with the plague

Solution:

VBA Code:
 With addMe.Resize(x - 1, 17).Borders
            .LineStyle = xlContinuous
            .Weight = xlThin
End With
 
Upvote 0
Solution

Forum statistics

Threads
1,223,885
Messages
6,175,183
Members
452,615
Latest member
bogeys2birdies

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