Autofit a Column based on range rather than the entire column

I have a worksheet with a number of headers that cover several columns.

If I use the standard auto fit command then result includes data in all rows.I could go back and restore columns with headers but even then I would be guessing at the correct width .

Is there any way to base the Autofit on a range rather than an entire column

Thanks

Belatedly, there is an autofit command; its argument is a range. So, if you wanted only the first five rows of column B to be used to set column B’s width, the command would look like this:

autofit every column of range "B1:B5"

Here is a more complete example. Run the following to put some text in some target cells:

tell application "Microsoft Excel"
	activate
	tell workbook 1
		tell active sheet
			set value of range "C2" to "command then result includes data"
			set value of range "C3" to "an entire column"		
			set use standard width of range "C2:C3" to true
		end tell
	end tell
end tell

Then run this on the resulting sheet. By changing the specified range, the column’s width can be controlled.

tell application "Microsoft Excel"
	tell workbook 1
		with timeout of 4 seconds
			tell active sheet
			-- autofit every column of range "C2:C2"
			autofit every column of range "C3:C3"		
		
			end tell
		end timeout
	end tell
end tell

Thank you very much better late than never

My pleasure. For whatever reason, I hadn’t seen the post until today. Maybe I wasn’t a member yet when it was posted.