Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ag Ag is offline
external usenet poster
 
Posts: 4
Default Create a macro which takes a column name and width and sets the column width to what it should be

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Create a macro which takes a column name and width and sets the co

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


  #3   Report Post  
Posted to microsoft.public.excel.programming
Ag Ag is offline
external usenet poster
 
Posts: 4
Default Create a macro which takes a column name and width and sets the co

On Sep 29, 7:31 pm, Joel 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
Ag Ag is offline
external usenet poster
 
Posts: 4
Default Create a macro which takes a column name and width and sets the co

On Sep 29, 8:29 pm, Ag wrote:
On Sep 29, 7:31 pm, Joel 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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Create a macro which takes a column name and width and sets th

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 wrote:
On Sep 29, 7:31 pm, Joel 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
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
Change Cell Width WITHOUT changing Column width dww701 Excel Discussion (Misc queries) 1 January 12th 09 10:52 PM
how do I create multiple column width in the same column in excel Vish Excel Discussion (Misc queries) 9 November 3rd 06 11:49 PM
How to make cell width different than the column width it lies in John Excel Discussion (Misc queries) 2 September 11th 06 10:41 PM
Set Column Width Based On Total Width Of Other Columns rayneraingoaway Excel Programming 1 June 28th 06 11:10 PM


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

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"