PC Review


Reply
Thread Tools Rate Thread

Columns by numbers

 
 
=?Utf-8?B?R2VvZmY=?=
Guest
Posts: n/a
 
      1st Nov 2006
I cannot work out how to refer to a group of columns by numbers.
this doesn't work or any varaition using Columns intead of Range:

Dim startCol as Byte, endCol as Byte

Range(Columns(startCol), Columns(startCol + 1), Columns(endCol)).AutoFit

Listing each column separately works but how can I group them on 1 line?

Columns(startCol).AutoFit
Columns(startCol +1).AutoFit
Columns(endCol).AutoFit

Could someone please help?

Geoff
 
Reply With Quote
 
 
 
 
=?Utf-8?B?SmltIEphY2tzb24=?=
Guest
Posts: n/a
 
      1st Nov 2006
Columns("A:G").autofit
--
Best wishes,

Jim


"Geoff" wrote:

> I cannot work out how to refer to a group of columns by numbers.
> this doesn't work or any varaition using Columns intead of Range:
>
> Dim startCol as Byte, endCol as Byte
>
> Range(Columns(startCol), Columns(startCol + 1), Columns(endCol)).AutoFit
>
> Listing each column separately works but how can I group them on 1 line?
>
> Columns(startCol).AutoFit
> Columns(startCol +1).AutoFit
> Columns(endCol).AutoFit
>
> Could someone please help?
>
> Geoff

 
Reply With Quote
 
=?Utf-8?B?R2VvZmY=?=
Guest
Posts: n/a
 
      1st Nov 2006
Hi Jim

Sorry - I said by numbers not letters

Geoff

"Jim Jackson" wrote:

> Columns("A:G").autofit
> --
> Best wishes,
>
> Jim
>
>
> "Geoff" wrote:
>
> > I cannot work out how to refer to a group of columns by numbers.
> > this doesn't work or any varaition using Columns intead of Range:
> >
> > Dim startCol as Byte, endCol as Byte
> >
> > Range(Columns(startCol), Columns(startCol + 1), Columns(endCol)).AutoFit
> >
> > Listing each column separately works but how can I group them on 1 line?
> >
> > Columns(startCol).AutoFit
> > Columns(startCol +1).AutoFit
> > Columns(endCol).AutoFit
> >
> > Could someone please help?
> >
> > Geoff

 
Reply With Quote
 
Toby Erkson
Guest
Posts: n/a
 
      1st Nov 2006
How about using a function to convert the number to a letter? For example,
here's a function I used when working with the first 26 (A-Z) columns:
-----
Function ConvertValue2Column(iValue As Integer) As String
'Takes a number and converts it into a letter to be used for cell column
calcs.

Dim Result As String, ASCIIVal As Integer

ASCIIVal = 64 'Asc("@")
If (ASCIIVal + iValue) > 90 Then
MsgBox "Table too long!", vbExclamation, "Error!"
Exit Function
End If
Result = Chr(ASCIIVal + iValue)
ConvertValue2Column = Result
End Function
-----

So, using the above function:
Range(Columns(ConvertValue2Column(startCol)),
Columns(ConvertValue2Column(startCol) + 1),
Columns(ConvertValue2Column(endCol))).AutoFit



"Geoff" <(E-Mail Removed)> wrote in message
news:BDF9C841-2BAB-413E-B964-(E-Mail Removed)...
>I cannot work out how to refer to a group of columns by numbers.
> this doesn't work or any varaition using Columns intead of Range:
>
> Dim startCol as Byte, endCol as Byte
>
> Range(Columns(startCol), Columns(startCol + 1), Columns(endCol)).AutoFit
>
> Listing each column separately works but how can I group them on 1 line?
>
> Columns(startCol).AutoFit
> Columns(startCol +1).AutoFit
> Columns(endCol).AutoFit



 
Reply With Quote
 
=?Utf-8?B?R2VvZmY=?=
Guest
Posts: n/a
 
      1st Nov 2006
Hi Toby
Yes, I have used a similar algorthm to convert letters to numbers. Just
seems a shame that a requirement so simple should require other code. If my
columns were contiguous then this would suffice:

Range(Columns(startCol), Columns(endCol)).AutoFit

.... but they need not be contiguous.

Seems like I need the sledgehammer after all <g>

Thanks

Geoff

"Toby Erkson" wrote:

> How about using a function to convert the number to a letter? For example,
> here's a function I used when working with the first 26 (A-Z) columns:
> -----
> Function ConvertValue2Column(iValue As Integer) As String
> 'Takes a number and converts it into a letter to be used for cell column
> calcs.
>
> Dim Result As String, ASCIIVal As Integer
>
> ASCIIVal = 64 'Asc("@")
> If (ASCIIVal + iValue) > 90 Then
> MsgBox "Table too long!", vbExclamation, "Error!"
> Exit Function
> End If
> Result = Chr(ASCIIVal + iValue)
> ConvertValue2Column = Result
> End Function
> -----
>
> So, using the above function:
> Range(Columns(ConvertValue2Column(startCol)),
> Columns(ConvertValue2Column(startCol) + 1),
> Columns(ConvertValue2Column(endCol))).AutoFit
>
>
>
> "Geoff" <(E-Mail Removed)> wrote in message
> news:BDF9C841-2BAB-413E-B964-(E-Mail Removed)...
> >I cannot work out how to refer to a group of columns by numbers.
> > this doesn't work or any varaition using Columns intead of Range:
> >
> > Dim startCol as Byte, endCol as Byte
> >
> > Range(Columns(startCol), Columns(startCol + 1), Columns(endCol)).AutoFit
> >
> > Listing each column separately works but how can I group them on 1 line?
> >
> > Columns(startCol).AutoFit
> > Columns(startCol +1).AutoFit
> > Columns(endCol).AutoFit

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
compare 2 columns of numbers and place the matched numbers in a 3r Clive Microsoft Excel Misc 5 8th Nov 2009 12:50 AM
Printing columns of numbers and align numbers Julian Microsoft Dot NET 0 28th Sep 2007 07:35 AM
split range of numbers in two columns to as many as numbers in ran =?Utf-8?B?YXJzb3ZhdA==?= Microsoft Excel Misc 2 30th Oct 2006 03:57 PM
Find similar numbers from two columns of numbers =?Utf-8?B?RGVubmlzIEFuZHJld3M=?= Microsoft Excel Misc 1 30th Nov 2005 07:54 AM
Numbers in columns =?Utf-8?B?SmVubg==?= Microsoft Excel Misc 2 7th Nov 2005 03:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:48 AM.