Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 287
Default Macro to copy certain data from one workbook into another

Hi,

I'm looking for a macro to do the following:

Copy columns B, D, G, and J from my currently opened active workbook,
and paste as a new workbook, whose file name excel would prompt the user to
give.

Conditions: The pasted columns when pasted should be next to eachother as if
the unwanted columns were cut and cells shifted over ( A[b]C[D]EF[G]HI[J] =
BDGJ ). The formatting of the new cells should be exact as the formatting
from the previous workbook (same column widths, same colors, etc.)

Please help. Thanks in advance.




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Macro to copy certain data from one workbook into another

Try this code

Sub CreateNewBook()

fileSaveName = Application.GetSaveAsFilename( _
Title:="Get New book filename", _
fileFilter:="Excel Files (*.xls), *.xls")
If fileSaveName = False Then
MsgBox ("Cannot Get filename - Exiting Macro")
Exit Sub
End If


ColArray = Array("B", "D", "G", "J")
DestCol = 1
Set SourceSht = ThisWorkbook.ActiveSheet

Set NewBk = Workbooks.Add(template:=xlWBATWorksheet)
Set NewSht = NewBk.Sheets(1)

With SourceSht
For Each Col In ColArray
.Columns(Col).Copy _
Destination:=NewSht.Columns(DestCol)
DestCol = DestCol + 1
Next Col
End With

NewBk.SaveAs Filename:=fileSaveName


End Sub


"Adam" wrote:

Hi,

I'm looking for a macro to do the following:

Copy columns B, D, G, and J from my currently opened active workbook,
and paste as a new workbook, whose file name excel would prompt the user to
give.

Conditions: The pasted columns when pasted should be next to eachother as if
the unwanted columns were cut and cells shifted over ( A[b]C[D]EF[G]HI[J] =
BDGJ ). The formatting of the new cells should be exact as the formatting
from the previous workbook (same column widths, same colors, etc.)

Please help. Thanks in advance.




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 287
Default Macro to copy certain data from one workbook into another

Works perfect. Will let you know if I run into any problems. Thank you so much.

"Joel" wrote:

Try this code

Sub CreateNewBook()

fileSaveName = Application.GetSaveAsFilename( _
Title:="Get New book filename", _
fileFilter:="Excel Files (*.xls), *.xls")
If fileSaveName = False Then
MsgBox ("Cannot Get filename - Exiting Macro")
Exit Sub
End If


ColArray = Array("B", "D", "G", "J")
DestCol = 1
Set SourceSht = ThisWorkbook.ActiveSheet

Set NewBk = Workbooks.Add(template:=xlWBATWorksheet)
Set NewSht = NewBk.Sheets(1)

With SourceSht
For Each Col In ColArray
.Columns(Col).Copy _
Destination:=NewSht.Columns(DestCol)
DestCol = DestCol + 1
Next Col
End With

NewBk.SaveAs Filename:=fileSaveName


End Sub


"Adam" wrote:

Hi,

I'm looking for a macro to do the following:

Copy columns B, D, G, and J from my currently opened active workbook,
and paste as a new workbook, whose file name excel would prompt the user to
give.

Conditions: The pasted columns when pasted should be next to eachother as if
the unwanted columns were cut and cells shifted over ( A[b]C[D]EF[G]HI[J] =
BDGJ ). The formatting of the new cells should be exact as the formatting
from the previous workbook (same column widths, same colors, etc.)

Please help. Thanks in advance.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro to copy certain data from one workbook into another

Can the results be appended to the same workbook ?

I have 3 or 4 workbooks from where i need to copy the date and make it as 1


"Adam" wrote:

Works perfect. Will let you know if I run into any problems. Thank you so much.

"Joel" wrote:

Try this code

Sub CreateNewBook()

fileSaveName = Application.GetSaveAsFilename( _
Title:="Get New book filename", _
fileFilter:="Excel Files (*.xls), *.xls")
If fileSaveName = False Then
MsgBox ("Cannot Get filename - Exiting Macro")
Exit Sub
End If


ColArray = Array("B", "D", "G", "J")
DestCol = 1
Set SourceSht = ThisWorkbook.ActiveSheet

Set NewBk = Workbooks.Add(template:=xlWBATWorksheet)
Set NewSht = NewBk.Sheets(1)

With SourceSht
For Each Col In ColArray
.Columns(Col).Copy _
Destination:=NewSht.Columns(DestCol)
DestCol = DestCol + 1
Next Col
End With

NewBk.SaveAs Filename:=fileSaveName


End Sub


"Adam" wrote:

Hi,

I'm looking for a macro to do the following:

Copy columns B, D, G, and J from my currently opened active workbook,
and paste as a new workbook, whose file name excel would prompt the user to
give.

Conditions: The pasted columns when pasted should be next to eachother as if
the unwanted columns were cut and cells shifted over ( A[b]C[D]EF[G]HI[J] =
BDGJ ). The formatting of the new cells should be exact as the formatting
from the previous workbook (same column widths, same colors, etc.)

Please help. Thanks in advance.




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
Macro copy data into another workbook Ingo Excel Programming 5 April 25th 08 11:12 AM
Macro Help. Copy data from 1 workbook to another on next available Howeecow Excel Discussion (Misc queries) 0 June 6th 07 08:29 PM
Macro to copy data into another workbook yukon_phil Excel Discussion (Misc queries) 0 July 26th 06 05:29 PM
Macro to copy data from one workbook to another supamari0 Excel Programming 1 June 19th 06 09:09 PM
Using Macro to copy latest data from one Workbook to another Kayote[_5_] Excel Programming 1 June 13th 06 07:01 PM


All times are GMT +1. The time now is 09:55 PM.

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"