PC Review


Reply
Thread Tools Rate Thread

Create a macro which takes a column name and width and sets the column width to what it should be

 
 
Ag
Guest
Posts: n/a
 
      29th Sep 2007
I want to create a macro whcich can be calles from a different sheet
and would change the column with to the parameter passed for the
column for whcich it is pased.The column name and width may be
mentioned in the second sheet from whcich they are read by the macro.

Aj

 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      29th Sep 2007
Enter the cell address in one cell and the width to the cell to the right.
Make the active cell the left of the two cells. for example below make cell
E1 the active cell when calling my macro below

E1 F1
A1 2

The above will make cell A1 columnwidth 2
For a different sheet

E1 F1
sheet2!A1 2


Then use this macro

Sub changewidth()

CellAddress = ActiveCell.Text
Cellwidth = ActiveCell.Offset(0, 1).Value

Range(CellAddress).ColumnWidth = Cellwidth

End Sub



"Ag" wrote:

> I want to create a macro whcich can be calles from a different sheet
> and would change the column with to the parameter passed for the
> column for whcich it is pased.The column name and width may be
> mentioned in the second sheet from whcich they are read by the macro.
>
> Aj
>
>

 
Reply With Quote
 
Ag
Guest
Posts: n/a
 
      29th Sep 2007
On Sep 29, 7:31 pm, Joel <J...@discussions.microsoft.com> wrote:
> Enter the cell address in one cell and the width to the cell to the right.
> Make the active cell the left of the two cells. for example below make cell
> E1 the active cell when calling my macro below
>
> E1 F1
> A1 2
>
> The above will make cell A1 columnwidth 2
> For a different sheet
>
> E1 F1
> sheet2!A1 2
>
> Then use this macro
>
> Sub changewidth()
>
> CellAddress = ActiveCell.Text
> Cellwidth = ActiveCell.Offset(0, 1).Value
>
> Range(CellAddress).ColumnWidth = Cellwidth
>
> End Sub
>
>
>
> "Ag" wrote:
> > I want to create a macro whcich can be calles from a different sheet
> > and would change the column with to the parameter passed for the
> > column for whcich it is pased.The column name and width may be
> > mentioned in the second sheet from whcich they are read by the macro.

>
> > Aj- Hide quoted text -

>
> - Show quoted text -


Great this works,
Now if i want to extend this such that
i want to have first column as sheet name
ie

> 1.csv E1 F1
> 1.csv A1 2
> 2.csv E1 F1

2.CSV A1 2
so that I can read each sheet and colun name so that the value of each
sheet and column name is null?
What would be the best way of doing this.Thanks in anticipation.

Ajay

 
Reply With Quote
 
Ag
Guest
Posts: n/a
 
      29th Sep 2007
On Sep 29, 8:29 pm, Ag <ajaygarg1...@gmail.com> wrote:
> On Sep 29, 7:31 pm, Joel <J...@discussions.microsoft.com> wrote:
>
>
>
>
>
> > Enter the cell address in one cell and the width to the cell to the right.
> > Make the active cell the left of the two cells. for example below make cell
> > E1 the active cell when calling my macro below

>
> > E1 F1
> > A1 2

>
> > The above will make cell A1 columnwidth 2
> > For a different sheet

>
> > E1 F1
> > sheet2!A1 2

>
> > Then use this macro

>
> > Sub changewidth()

>
> > CellAddress = ActiveCell.Text
> > Cellwidth = ActiveCell.Offset(0, 1).Value

>
> > Range(CellAddress).ColumnWidth = Cellwidth

>
> > End Sub

>
> > "Ag" wrote:
> > > I want to create a macro whcich can be calles from a different sheet
> > > and would change the column with to the parameter passed for the
> > > column for whcich it is pased.The column name and width may be
> > > mentioned in the second sheet from whcich they are read by the macro.

>
> > > Aj- Hide quoted text -

>
> > - Show quoted text -

>
> Great this works,
> Now if i want to extend this such that
> i want to have first column as sheet name
> ie
>
> > 1.csv E1 F1
> > 1.csv A1 2
> > 2.csv E1 F1

>
> 2.CSV A1 2
> so that I can read each sheet and colun name so that the value of each
> sheet and column name is null?
> What would be the best way of doing this.Thanks in anticipation.
>
> Ajay- Hide quoted text -
>
> - Show quoted text -


I get the error method range of object global failed.Am I doing
something wrong?

Ajay

 
Reply With Quote
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      29th Sep 2007
Did you remember to put in the '!' character between the sheetname and the
cell address?

Sub changewidth()

CellSheet = ActiveCell.Text
CellAddress = ActiveCell.Offset(0, 1).Text
Cellwidth = ActiveCell.Offset(0, 2).Value

Range(CellSheet & "!" & _
CellAddress).ColumnWidth = Cellwidth

End Sub

"Ag" wrote:

> On Sep 29, 8:29 pm, Ag <ajaygarg1...@gmail.com> wrote:
> > On Sep 29, 7:31 pm, Joel <J...@discussions.microsoft.com> wrote:
> >
> >
> >
> >
> >
> > > Enter the cell address in one cell and the width to the cell to the right.
> > > Make the active cell the left of the two cells. for example below make cell
> > > E1 the active cell when calling my macro below

> >
> > > E1 F1
> > > A1 2

> >
> > > The above will make cell A1 columnwidth 2
> > > For a different sheet

> >
> > > E1 F1
> > > sheet2!A1 2

> >
> > > Then use this macro

> >
> > > Sub changewidth()

> >
> > > CellAddress = ActiveCell.Text
> > > Cellwidth = ActiveCell.Offset(0, 1).Value

> >
> > > Range(CellAddress).ColumnWidth = Cellwidth

> >
> > > End Sub

> >
> > > "Ag" wrote:
> > > > I want to create a macro whcich can be calles from a different sheet
> > > > and would change the column with to the parameter passed for the
> > > > column for whcich it is pased.The column name and width may be
> > > > mentioned in the second sheet from whcich they are read by the macro.

> >
> > > > Aj- Hide quoted text -

> >
> > > - Show quoted text -

> >
> > Great this works,
> > Now if i want to extend this such that
> > i want to have first column as sheet name
> > ie
> >
> > > 1.csv E1 F1
> > > 1.csv A1 2
> > > 2.csv E1 F1

> >
> > 2.CSV A1 2
> > so that I can read each sheet and colun name so that the value of each
> > sheet and column name is null?
> > What would be the best way of doing this.Thanks in anticipation.
> >
> > Ajay- Hide quoted text -
> >
> > - Show quoted text -

>
> I get the error method range of object global failed.Am I doing
> something wrong?
>
> Ajay
>
>

 
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
cannot paste source column width to destination column width transkawa Microsoft Excel New Users 1 15th Oct 2010 04:09 PM
Dynamically Resize Gridview Width Property (NOT Column Width) Hartman_Ralph@Hotmail.com Microsoft ASP .NET 0 2nd Jun 2009 04:59 PM
Change table width when changing width of a column Tom Doster Microsoft Powerpoint 0 9th Jan 2009 03:52 PM
how do I create multiple column width in the same column in excel =?Utf-8?B?VmlzaA==?= Microsoft Excel Misc 9 3rd Nov 2006 11:49 PM
sum of multiple columns width differs from single column width Sven Passig Microsoft Excel Programming 0 4th Feb 2004 10:16 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:31 AM.