Share via

Help with setting column width within a script in Excel

Anonymous
2025-04-01T13:52:09+00:00

I'm getting errors when trying to set column widths within an excel script. I keep getting hit with "Property 'setColumnWidth' does not exist on type 'Range'."

What is correct to use? I'm not sure what I'm doing wrong here. I've seen that others have had similar issues, and copilot is telling me this should work as well.

    selectedSheet.getRange("C:E").setColumnWidth(10);

Microsoft 365 and Office | Excel | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Anonymous
    2025-04-01T15:30:35+00:00

    When I record a column width change script, I get code with getFormat(), like:

    selectedSheet.getRange("C:E").getFormat().setColumnWidth(10);

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments