Copying cell formats

iisailor

Board Regular
Joined
Feb 18, 2009
Messages
58
The following is a brilliant bit of code that users on here helped me to create. It does what i need perfectly however my question is: How can i change the code to copy the format of the worksheet. Basically overall the macro works with other subroutines and functions to create a new worksheet, copy into it all the results of a search criteria then attach this sheet to the body of an email. The problem however is that when it attaches it to the email it keeps the format from the newly created worksheet which and such it tends to lose some details becasue the cells arent wide enough to show all the data.
Any suggestions folks
Thanks in advance
Chris

Code:
Sub mycodes()
Dim x As Long, a As Long, b As Long, d As Long, y As Long
x = Sheets("2672 - Traceys").cells(Rows.Count, 3).End(xlUp).Row
y = Sheets("2672 - Traceys").cells(Rows.Count, 26).End(xlUp).Row
For b = 1 To y
CreateTemp
d = 1
For a = 2 To x
If Sheets("2672 - Traceys").cells(a, 5) = Sheets("2672 - Traceys").cells(b, 26) Then
Sheets("2672 - Traceys").Rows(a).Copy
d = Sheets("SearchResults").cells(Rows.Count, 1).End(xlUp).Row
Sheets("SearchResults").Rows(d + 1).PasteSpecial
End If
Next a
d = d + 1
Sheets("SearchResults").Select
MsgBox "Email for  " & Sheets("2672 - Traceys").cells(b, 26)
Call Mail_Selection_Range_Outlook_Body
    Application.DisplayAlerts = False
    Worksheets("SearchResults").Delete
    Application.DisplayAlerts = True
Next b
End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Alternatively if its possible, when creating a new sheet, to format the cells to shrink and expand to fit the text that would be just as perfect.
Thanks again
Chris
 
Upvote 0
AutoFit in a column is not a Cell Format, it is a Column Format and you are copying cells, not columns.
To automate something like this:
Setup event code to autoformat your columns.

-or-

For a one time column Format;
Add a line of code similar to this after the copy:
Code:
Sheets("SearchResults").Columns.AutoFit
 
Upvote 0
Thanks for the advice Datsmart. Jiggled my code a little and got the problem sorted.
Genuinely thank you very much
Chris
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,479
Members
448,967
Latest member
visheshkotha

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