Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default copying range column widths

Greetings

Is there a quick way to apply a range's column widths to another range

For example, a user may populate a query table, delete some columns, adjust some columns to their liking, and then copy that modified range to another worksheet

I can copy and paste a ranges's data into another worksheet, but I can't (easily) preserve the column widths of the original range. Is there some slick code to copy the original ranges's column widths to the copied ranges columns without looping

Thanks a lot
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default copying range column widths

If you use Excel 2000 or higher you can use PasteSpecial

Sheets("Sheet1").Range("A1:D1").Copy
Sheets("Sheet2").Range("a1").PasteSpecial Paste:=8
' Paste:=8 will copy the column width in Excel 2000 and higher
Application.CutCopyMode = False


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"rexsalius" wrote in message ...
Greetings,

Is there a quick way to apply a range's column widths to another range?

For example, a user may populate a query table, delete some columns, adjust some columns to their liking, and then copy that

modified range to another worksheet.

I can copy and paste a ranges's data into another worksheet, but I can't (easily) preserve the column widths of the original

range. Is there some slick code to copy the original ranges's column widths to the copied ranges columns without looping?

Thanks a lot



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default copying range column widths

rexsalius wrote:
Greetings,

Is there a quick way to apply a range's column widths to another range?

For example, a user may populate a query table, delete some columns, adjust some columns to their liking, and then copy that modified range to another worksheet.

I can copy and paste a ranges's data into another worksheet, but I can't (easily) preserve the column widths of the original range. Is there some slick code to copy the original ranges's column widths to the copied ranges columns without looping?


Here is another way that doesn't involve selection of the range.

Sub CopyColumnWidths()
For i = 1 To Range("A:J").Columns.Count
Sheets("Sheet2").Range("A:J").Columns(i).ColumnWid th = _
Sheets("Sheet1").Range("A:J").Columns(i).ColumnWid th
Next i
End Sub

Regards,
--
Beto
Reply: Erase between the dot (inclusive) and the @.
Responder: Borra la frase obvia y el punto previo.

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
Copying formats - column widths, formats, outlining to worksheets DavidBr318 Excel Worksheet Functions 4 August 14th 09 05:03 AM
Different widths for each column in a 100% stacked column chart Chart Explorer Charts and Charting in Excel 1 May 21st 09 09:19 AM
copying Excel column names and widths to a blank spreadsheet Louis B Moskowitz Excel Discussion (Misc queries) 1 June 7th 07 12:36 PM
One column with various widths RichardGolf72 Excel Worksheet Functions 2 June 7th 06 07:54 PM
Column widths are the same but look different. Suzan Excel Discussion (Misc queries) 0 December 29th 05 04:29 PM


All times are GMT +1. The time now is 08:47 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"