ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro to set the colomns width (https://www.excelbanter.com/excel-programming/333270-macro-set-colomns-width.html)

Jean-Jerome Doucet via OfficeKB.com

Macro to set the colomns width
 
Hi,

I would like to create a macro that set the columns width for my Excel form.

It must probably look like what's quoted at the end of this message. The
problem is that it is a macro that is active permenently on the page when you
edit the cells. I want a macro that set the width on demand. Any ideas?
Thx!

Werner

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Select Case Target.Column
Case 1, 3, 5 To 8
Target.ColumnWidth = 2
Case 2, 4
Target.ColumnWidth = 7
End Select
End Sub

--
Message posted via http://www.officekb.com

Anne Troy[_2_]

Macro to set the colomns width
 
Hello, Jean-Jerome. You can record this macro as long as your columns won't
be moving around.

http://www.officearticles.com/excel/...soft_excel.htm

*******************
~Anne Troy

www.OfficeArticles.com
www.MyExpertsOnline.com


"Jean-Jerome Doucet via OfficeKB.com" wrote in message
...
Hi,

I would like to create a macro that set the columns width for my Excel

form.

It must probably look like what's quoted at the end of this message. The
problem is that it is a macro that is active permenently on the page when

you
edit the cells. I want a macro that set the width on demand. Any ideas?
Thx!

Werner

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Select Case Target.Column
Case 1, 3, 5 To 8
Target.ColumnWidth = 2
Case 2, 4
Target.ColumnWidth = 7
End Select
End Sub

--
Message posted via http://www.officekb.com




Tom Ogilvy

Macro to set the colomns width
 
Sub SetColumns()
Dim i as Long
for i = 1 to 8
Select Case i
Case 1, 3, 5 To 8
columns(i).ColumnWidth = 2
Case 2, 4
columns(i).ColumnWidth = 7
End Select
Next
End Sub

--
Regards,
Tom Ogilvy

"Jean-Jerome Doucet via OfficeKB.com" wrote in message
...
Hi,

I would like to create a macro that set the columns width for my Excel

form.

It must probably look like what's quoted at the end of this message. The
problem is that it is a macro that is active permenently on the page when

you
edit the cells. I want a macro that set the width on demand. Any ideas?
Thx!

Werner

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Select Case Target.Column
Case 1, 3, 5 To 8
Target.ColumnWidth = 2
Case 2, 4
Target.ColumnWidth = 7
End Select
End Sub

--
Message posted via http://www.officekb.com




Jean-Jerome Doucet via OfficeKB.com

Macro to set the colomns width
 
Thank you to both of you. It wolved my problem.

Jean-Jérôme

--
Message posted via http://www.officekb.com


All times are GMT +1. The time now is 02:57 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com