Use Offset with Columns()

288enzo

Well-known Member
Joined
Feb 8, 2009
Messages
721
Office Version
  1. 2016
Platform
  1. Windows
Is it possible to use Offset with Columns()? I'm getting an error, so either the answer is no, or there is something I'm missing. I've been searching and searching, I haven't found anything that says I can't, but on the other hand, I haven't found anything that says I can.

Application-defined or object-defined error​


VBA Code:
    With Sheets("employees")
        With .Cells.Font
            .Size = 9
        End With
        With .Columns(14)
            .EntireColumn.Insert
            .Offset(-1).ColumnWidth = 10.71
        End With
End With

Without the offset, Columns(15) is formatted to 10.71.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
When using Offset, the parameters are Offset(rows, columns), so perhaps try ".Offset(0, -1).ColumnWidth = 10.71"
 
Upvote 0
Solution
When using Offset, the parameters are Offset(rows, columns), so perhaps try ".Offset(0, -1).ColumnWidth = 10.71"
Thanks, silly mistake. Much appreciated. Missing a comma

VBA Code:
    With Sheets("employees")
        With .Cells.Font
            .Size = 9
        End With
        With .Columns(14)
            .EntireColumn.Insert
            .Offset(,-1).ColumnWidth = 10.71
        End With
End With
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,583
Members
449,089
Latest member
Motoracer88

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