LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Copy specified columns to another sheet

OK try this: Make the sheet you want to copy from the active sheet before
you run this.

Sub Copy()
Dim StdWidth As Long, MyWidth As Long, i As Integer
Dim sh As String, WrkSht As Worksheet

sh = ActiveSheet.Name
For Each WrkSht In Worksheets
If WrkSht.Name = "Report" Then
MsgBox ("A sheet named Report already exists")
Exit Sub
End If
Next
Worksheets.Add.Name = "Report"
Worksheets(sh).Range("A:F,H:H,U:U,X:Y").Copy Range("A1")
Columns("A:J").AutoFit
StdWidth = Columns(11).ColumnWidth 'unused column
For i = 1 To 10
MyWidth = Columns(i).ColumnWidth
Next
If MyWidth StdWidth Then
Columns("A:J").ColumnWidth = MyWidth
Else
Columns("A:J").ColumnWidth = StdWidth
End If
End Sub

You wanted to make the pasted columns uniform in width. 10 columns were
pasted to the new sheet.
I AutoFit these columns to the contents in them.
I then check the width of an unused column (11)
The For i = 1 to 10 code will find the widest column in the 10 columns that
were pasted.
If any of those columns are wider than a default column width (column 11)
then make all 10 columns that widest width.
If all 10 columns are less in width than the default width, then make all
10 columns the default width.
This will give some uniformity to those column widths.

Mike F

"Gemz" wrote in message
...
I tried pasting this into a VB module but already it displayed the first
line
as red..."Columns("A:F, H, U, X, Y").Copy
Worksheets("Sheet2").Range("A1")."
meaning there is something wrong with this line. i have put 'sub and a
name'
just before this line but dont know why its not working.

also when you make reference to sheet 2, do you mean this info will be
copied into sheet 2 only if there is a sheet existing with the name sheet
2?
can i not jus say copy into another sheet which is non-existant and for
the
macro to create it and name it report?

finally, what do you mean by "For i = 1 To 10"

thanks in advance for all your help.

"Mike Fogleman" wrote:

Assuming you have already applied the filter:
Columns("A:F, H, U, X, Y").Copy Worksheets("Sheet2").Range("A1").
Worksheets("Sheet2").Columns("A:J").AutoFit
Dim StdWidth As Long, MyWidth As Long, i As Integer
StdWidth = Columns(11).ColumnWidth 'unused column
For i = 1 To 10
MyWidth = Columns(i).ColumnWidth
Next
If MyWidth StdWidth Then
Columns("A:J").ColumnWidth = MyWidth
Else
Columns("A:J").ColumnWidth = StdWidth
End If

Mike F

"Gemz" wrote in message
...
I'd like to tell a macro to copy specified columns after it has
filtered
for
a criteria - wich is if column U is blank to hide these rows and then
copy
columns A,B,C,D,E,F,H,Y,U,X to another sheet within the same workbook.
if
possible i would also like to tell the macro to format the data in some
way
because when i manually copied across, the column widths etc were not
the
same size and it just looked messy, can i also tell the macro to do
this?

please reply at your earliest possible convinience,

many thanks.






 
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
Copy Columns to New Sheet manfareed Excel Programming 4 December 21st 07 10:56 AM
copy different columns from sheet to other sheet p. panter Excel Programming 1 February 9th 06 05:23 PM
Copy certain columns to another sheet using a macro Shane Nation Excel Programming 2 September 24th 05 05:36 PM
Copy a row from one sheet to another and not all columns copy Peaches[_2_] Excel Programming 2 September 7th 05 12:09 PM
macro to copy columns to sheet Es Excel Discussion (Misc queries) 1 March 7th 05 02:03 PM


All times are GMT +1. The time now is 01:48 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"