Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Using variables to reference columns in VBA
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 -- Message posted from http://www.ExcelForum.com |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Using variables to reference columns in VBA
aktiv
Try txtColumnStart = "A" txtColumEnd = "C" Columns(txtColumnStart & ":" & txtColumEnd).ColumnWidth = txtColumnWidth --- Message posted from http://www.ExcelForum.com/ |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Using variables to reference columns in VBA
I knew that it would be something simple!
That did the trick - thanks a lot. Keith -- Message posted from http://www.ExcelForum.com |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Using variables to reference columns in VBA
You can also use numbers to identify your columns
x = y = 1 ActiveSheet.Range(Columns(x), Columns(y)).ColumnWidth = txtColumnWidt ----- aktiv wrote: ---- 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 -- Message posted from http://www.ExcelForum.com |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Reference a file by concatenating cell variables | Excel Worksheet Functions | |||
Need to reference another sheet for two variables | Excel Worksheet Functions | |||
Syntax for using variables in a cell formula to reference paths/fi | Excel Worksheet Functions | |||
Vary variables in a formula via reference to another cell | Excel Discussion (Misc queries) | |||
countif two variables in two different columns | Excel Worksheet Functions |