Don’t you mean “… for a column that is variable)? You can use
Range(Cells(1, 3), Cells(1, ColCnt))
or
Range(“C1”).Resize(1, ColCnt – 2)
(and the method to select a range is .Select, not .Selection)
![]() |
There are isolated problems with current patches, but they are well-known and documented on this site. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Setting Range? (Excel 2003)
Can anyone tell me the format for setting a Range for a Columns that are variable.
I have determined the numeric position of the last column and stored it in a variable called ColCnt. If it is 7 then I want Cell ‘G1’ if it is 27 then ‘AA1’
What I need is if ColCnt = 7 then
Range(“C1:G1”).select
Thank you
See Column Numbers To Letters for a function that convets the number to the corresponding column letters.
Hi Hans:
I find that this cells syntax within the Range method fails when I automate Excel from Access via VBA using Office 2003 on Windows XP.
For example:
Worksheets(“Sheet1”).Range(Cells(1, 1), Cells(5, 3)).Font.Italic = True
and
Set rng = osheet.Range(Cells(1, 1), Cells(1, intCols))
both fail. Any idea why or how to fix it?
Thanks!
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.