Extracting data from a different workbook and creating multiple workbooks - how to format

Holley

Board Regular
Joined
Dec 11, 2019
Messages
120
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Thanks for all the past help I've received from the forum! It has been a lifesaver! I have a question I hope you can help with. I have a very large file with usually 2,000 - 3,000 rows. I have a macro that will extract all the rows with matching data in column C and put them into a new workbook and save the file with the value of column C. My problem is that the format is lost when the new file is created. Can anyone shed any light to help me retain the format? Its mixed with date, currency, etc.

Thanks again!
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Do you have a snippet of the code? Probably just need to include the formatting depending on how it's putting data in the new workbook
 
Upvote 0
I run this first...
1576791835231.png




then this
1576792349216.png

1576792609191.png
 
Upvote 0
Its set to email them, but I don't want to do that, so I've removed it from the code.
 
Upvote 0
So I think you just need to change it from Cells.PasteSpecial xlPasteValues to Cells.PasteSpecial xlPasteAllUsingSourceTheme
 
Upvote 0
The data is perfect!! But, it didn't retain the layout of the page. I need for it to be landscape, narrow margins and fit all columns to one page. Would that be possible?
 
Upvote 0
You'll want to add this right before you save it.

VBA Code:
  With Destwb.PageSetup
        .LeftMargin = Application.InchesToPoints(0.25)
        .RightMargin = Application.InchesToPoints(0.25)
        .TopMargin = Application.InchesToPoints(0.75)
        .BottomMargin = Application.InchesToPoints(0.75)
        .HeaderMargin = Application.InchesToPoints(0.3)
        .FooterMargin = Application.InchesToPoints(0.3)
        .Orientation = xlLandscape
        .FitToPagesWide = 1
        .FitToPagesTall = 1
    End With
 
Upvote 0
I'm sure I haven't entered this in the correct place. I get a Run-time error '438': Object doesn't support this property or method. I entered it just before:

'Save the new workbook, email it, and close it
'Set otlNewMail = otlApp.CreateItem(olMailItem)
With Destwb
.SaveAs FolderName _
& "\" & Destwb.Sheets(1).Name & FileExtStr, _
FileFormat:=FileFormatNum
End With

Thanks again for your help and please pardon my ignorance.:)
 
Upvote 0
I'm sure I haven't entered this in the correct place. I get a Run-time error '438': Object doesn't support this property or method. I entered it just before:

Thanks again for your help and please pardon my ignorance.:)

I forgot the sheet..

VBA Code:
     With Destwb.Sheets(1).PageSetup
        .LeftMargin = Application.InchesToPoints(0.25)
        .RightMargin = Application.InchesToPoints(0.25)
        .TopMargin = Application.InchesToPoints(0.75)
        .BottomMargin = Application.InchesToPoints(0.75)
        .HeaderMargin = Application.InchesToPoints(0.3)
        .FooterMargin = Application.InchesToPoints(0.3)
        .Orientation = xlLandscape
        .FitToPagesWide = 1
        .FitToPagesTall = 1
    End With
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,941
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top