PC Review


Reply
Thread Tools Rate Thread

Code to adjust column width

 
 
primed
Guest
Posts: n/a
 
      15th Apr 2010
Hi,

Can anyone help with code to do the following:

Row E8:AI8 - each cell contains a value 0 to 100, generally a value of 1 to
20. The total of the row is maximum 100.
I would like to adjust the width of the column based on the values for each
column.
The minimum width would need to be 6 so text is still readable.

Thanks in advance

Primed
 
Reply With Quote
 
 
 
 
Per Jessen
Guest
Posts: n/a
 
      15th Apr 2010
Hi Primed

This should do it:

Sub ColumnAdjust()
Set Rng = Range("E8:AI8")
For Each cell In Rng
If cell.Value >= 6 Then
cell.ColumnWidth = cell.Value
Else
cell.ColumnWidth = 6
End If
Next
End Sub

Regards,
Per

"primed" <(E-Mail Removed)> skrev i meddelelsen
news:FAB13FFF-37FD-44C7-9D3F-(E-Mail Removed)...
> Hi,
>
> Can anyone help with code to do the following:
>
> Row E8:AI8 - each cell contains a value 0 to 100, generally a value of 1
> to
> 20. The total of the row is maximum 100.
> I would like to adjust the width of the column based on the values for
> each
> column.
> The minimum width would need to be 6 so text is still readable.
>
> Thanks in advance
>
> Primed


 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      15th Apr 2010
Why not let VB figure it out for you...

Columns("E:AI").AutoFit

--
Rick (MVP - Excel)



"primed" <(E-Mail Removed)> wrote in message
news:FAB13FFF-37FD-44C7-9D3F-(E-Mail Removed)...
> Hi,
>
> Can anyone help with code to do the following:
>
> Row E8:AI8 - each cell contains a value 0 to 100, generally a value of 1
> to
> 20. The total of the row is maximum 100.
> I would like to adjust the width of the column based on the values for
> each
> column.
> The minimum width would need to be 6 so text is still readable.
>
> Thanks in advance
>
> Primed


 
Reply With Quote
 
primed
Guest
Posts: n/a
 
      16th Apr 2010
I am not a programmer but that doesnt seem to take into account the values in
row 8.
It will come in handy for something else though.

Cheers
Primed

"Rick Rothstein" wrote:

> Why not let VB figure it out for you...
>
> Columns("E:AI").AutoFit
>
> --
> Rick (MVP - Excel)
>
>
>
> "primed" <(E-Mail Removed)> wrote in message
> news:FAB13FFF-37FD-44C7-9D3F-(E-Mail Removed)...
> > Hi,
> >
> > Can anyone help with code to do the following:
> >
> > Row E8:AI8 - each cell contains a value 0 to 100, generally a value of 1
> > to
> > 20. The total of the row is maximum 100.
> > I would like to adjust the width of the column based on the values for
> > each
> > column.
> > The minimum width would need to be 6 so text is still readable.
> >
> > Thanks in advance
> >
> > Primed

>
> .
>

 
Reply With Quote
 
primed
Guest
Posts: n/a
 
      16th Apr 2010
Cheers,

Worked great.
I modified slightly.

Sub ColumnAdjust()
Set Rng = Range("E8:AI8")
For Each cell In Rng
If cell.Value >= 1 Then
cell.ColumnWidth = cell.Value * 6
Else
cell.ColumnWidth = 0
End If
Next
End Sub

"Per Jessen" wrote:

> Hi Primed
>
> This should do it:
>
> Sub ColumnAdjust()
> Set Rng = Range("E8:AI8")
> For Each cell In Rng
> If cell.Value >= 6 Then
> cell.ColumnWidth = cell.Value
> Else
> cell.ColumnWidth = 6
> End If
> Next
> End Sub
>
> Regards,
> Per
>
> "primed" <(E-Mail Removed)> skrev i meddelelsen
> news:FAB13FFF-37FD-44C7-9D3F-(E-Mail Removed)...
> > Hi,
> >
> > Can anyone help with code to do the following:
> >
> > Row E8:AI8 - each cell contains a value 0 to 100, generally a value of 1
> > to
> > 20. The total of the row is maximum 100.
> > I would like to adjust the width of the column based on the values for
> > each
> > column.
> > The minimum width would need to be 6 so text is still readable.
> >
> > Thanks in advance
> >
> > Primed

>
> .
>

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      16th Apr 2010
I'm not sure why you say that... the code line I posted sizes each column in
the range to the contents of the widest value in the column (which, unless I
completely misunderstood what you were asking for, I believe is what your
initial posting was suggesting you wanted to do). If you didn't already do
so, give it a try and see how it works.

--
Rick (MVP - Excel)



"primed" <(E-Mail Removed)> wrote in message
news:556C62C8-4243-4645-8850-(E-Mail Removed)...
> I am not a programmer but that doesnt seem to take into account the values
> in
> row 8.
> It will come in handy for something else though.
>
> Cheers
> Primed
>
> "Rick Rothstein" wrote:
>
>> Why not let VB figure it out for you...
>>
>> Columns("E:AI").AutoFit
>>
>> --
>> Rick (MVP - Excel)
>>
>>
>>
>> "primed" <(E-Mail Removed)> wrote in message
>> news:FAB13FFF-37FD-44C7-9D3F-(E-Mail Removed)...
>> > Hi,
>> >
>> > Can anyone help with code to do the following:
>> >
>> > Row E8:AI8 - each cell contains a value 0 to 100, generally a value of
>> > 1
>> > to
>> > 20. The total of the row is maximum 100.
>> > I would like to adjust the width of the column based on the values for
>> > each
>> > column.
>> > The minimum width would need to be 6 so text is still readable.
>> >
>> > Thanks in advance
>> >
>> > Primed

>>
>> .
>>

 
Reply With Quote
 
primed
Guest
Posts: n/a
 
      21st Apr 2010
Hi Rick,

Probably my poor communication skills are the issue. Columns E to AI need to
be resized based on values in row 8 only. Other rows contain data that needs
to be ignored.

Your formula seems to resize the columns based on the value in all the rows.

Regards
Primed

"Rick Rothstein" wrote:

> I'm not sure why you say that... the code line I posted sizes each column in
> the range to the contents of the widest value in the column (which, unless I
> completely misunderstood what you were asking for, I believe is what your
> initial posting was suggesting you wanted to do). If you didn't already do
> so, give it a try and see how it works.
>
> --
> Rick (MVP - Excel)
>
>
>
> "primed" <(E-Mail Removed)> wrote in message
> news:556C62C8-4243-4645-8850-(E-Mail Removed)...
> > I am not a programmer but that doesnt seem to take into account the values
> > in
> > row 8.
> > It will come in handy for something else though.
> >
> > Cheers
> > Primed
> >
> > "Rick Rothstein" wrote:
> >
> >> Why not let VB figure it out for you...
> >>
> >> Columns("E:AI").AutoFit
> >>
> >> --
> >> Rick (MVP - Excel)
> >>
> >>
> >>
> >> "primed" <(E-Mail Removed)> wrote in message
> >> news:FAB13FFF-37FD-44C7-9D3F-(E-Mail Removed)...
> >> > Hi,
> >> >
> >> > Can anyone help with code to do the following:
> >> >
> >> > Row E8:AI8 - each cell contains a value 0 to 100, generally a value of
> >> > 1
> >> > to
> >> > 20. The total of the row is maximum 100.
> >> > I would like to adjust the width of the column based on the values for
> >> > each
> >> > column.
> >> > The minimum width would need to be 6 so text is still readable.
> >> >
> >> > Thanks in advance
> >> >
> >> > Primed
> >>
> >> .
> >>

> .
>

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      21st Apr 2010
Ah, I missed the Row 8 part. Give this a try then...

Range("E8:AI8").Columns.AutoFit

--
Rick (MVP - Excel)



"primed" <(E-Mail Removed)> wrote in message
news:06B8210D-6805-47A7-AEA2-(E-Mail Removed)...
> Hi Rick,
>
> Probably my poor communication skills are the issue. Columns E to AI need
> to
> be resized based on values in row 8 only. Other rows contain data that
> needs
> to be ignored.
>
> Your formula seems to resize the columns based on the value in all the
> rows.
>
> Regards
> Primed
>
> "Rick Rothstein" wrote:
>
>> I'm not sure why you say that... the code line I posted sizes each column
>> in
>> the range to the contents of the widest value in the column (which,
>> unless I
>> completely misunderstood what you were asking for, I believe is what your
>> initial posting was suggesting you wanted to do). If you didn't already
>> do
>> so, give it a try and see how it works.
>>
>> --
>> Rick (MVP - Excel)
>>
>>
>>
>> "primed" <(E-Mail Removed)> wrote in message
>> news:556C62C8-4243-4645-8850-(E-Mail Removed)...
>> > I am not a programmer but that doesnt seem to take into account the
>> > values
>> > in
>> > row 8.
>> > It will come in handy for something else though.
>> >
>> > Cheers
>> > Primed
>> >
>> > "Rick Rothstein" wrote:
>> >
>> >> Why not let VB figure it out for you...
>> >>
>> >> Columns("E:AI").AutoFit
>> >>
>> >> --
>> >> Rick (MVP - Excel)
>> >>
>> >>
>> >>
>> >> "primed" <(E-Mail Removed)> wrote in message
>> >> news:FAB13FFF-37FD-44C7-9D3F-(E-Mail Removed)...
>> >> > Hi,
>> >> >
>> >> > Can anyone help with code to do the following:
>> >> >
>> >> > Row E8:AI8 - each cell contains a value 0 to 100, generally a value
>> >> > of
>> >> > 1
>> >> > to
>> >> > 20. The total of the row is maximum 100.
>> >> > I would like to adjust the width of the column based on the values
>> >> > for
>> >> > each
>> >> > column.
>> >> > The minimum width would need to be 6 so text is still readable.
>> >> >
>> >> > Thanks in advance
>> >> >
>> >> > Primed
>> >>
>> >> .
>> >>

>> .
>>

 
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
Column Width: cannot adjust =?Utf-8?B?ZmFsY2lvcw==?= Microsoft Excel Misc 1 3rd Nov 2007 02:49 PM
Adjust column width =?Utf-8?B?dGxlZQ==?= Microsoft Excel Misc 2 4th May 2006 11:58 PM
Adjust Column Width? =?Utf-8?B?Q0RBSw==?= Microsoft Excel Misc 0 16th Jun 2005 10:26 PM
adjust column width =?Utf-8?B?Y29vbGJlYW5z?= Microsoft Excel Misc 1 15th May 2005 12:34 PM
Using Code to Adjust Specific Column Width Nigel Bennett Microsoft Excel Programming 4 9th Mar 2005 06:11 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:11 PM.