Using variables to reference columns in VBA

A

aktiv

I need to be able to change the width of a contiguous selection o
columns. I know how to do this with pre-determined columns with th
user-specified width "txtColumnWidth":> Columns("A:E").ColumnWidth = txtColumnWidthHowever, in this case the columns are specifed via the user in a for
using the variables "txtColumnStart" and "txtColumnEnd". I would thin
that> Columns(txtColumnStart, txtColumEnd).ColumnWidth = txtColumnWidthwould be the solution, but I get a "Run-time error '1004'
Application-defined or object-defined error" message.

How does one specify column sets from variables for this kind o
activity?

Thanks!

Keith
 
M

mudraker

aktiv

Try

txtColumnStart = "A"
txtColumEnd = "C"
Columns(txtColumnStart & ":" & txtColumEnd).ColumnWidth =
txtColumnWidth
 
Top