Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 244
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reference a file by concatenating cell variables Michael Excel Worksheet Functions 13 October 24th 08 09:54 PM
Need to reference another sheet for two variables I M Desperate!!![_2_] Excel Worksheet Functions 1 June 14th 08 05:39 PM
Syntax for using variables in a cell formula to reference paths/fi colorado808 Excel Worksheet Functions 4 March 15th 07 03:41 AM
Vary variables in a formula via reference to another cell Peter Excel Discussion (Misc queries) 2 July 21st 05 07:19 PM
countif two variables in two different columns Greg Diamond Excel Worksheet Functions 2 May 25th 05 07:58 PM


All times are GMT +1. The time now is 12:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"