Formatting New Worksheet in VB?

  • 13 years ago

    Does anyone know the code that I need to use to auto-format a new worksheet?  I have a VB macro that copys a worksheet, opens a new worksheet, and pastes the contents.  How do I automatically format the new worksheet so it matches the original?   Cheers.

  • 13 years ago

    Hello

    90 % of your work is done. 

    Just try this .It might help.

    While Parting the contents use "PasteSpecial ". For example If you have selected the range which has to be pasted on another worksheet without changing the format  : try

    Selection.PasteSpecial Paste:=xlPasteFormulasAndNumberFormats

    I hope this should solve your problem.

    Ash

  • 13 years ago

    If I have understood you correctly, you want to copy and paste a complete worksheet. That could easily be achieved by using the worksheet.copy procedure. You just need to declare after or before which worksheet the new worksheet should be inserted.

    If you want to create a new workbook, just dont pass any parameter.

     

    http://msdn2.microsoft.com/en-us/library/microsoft.office.interop.excel._worksheet.copy(VS.90).aspx

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The generation of random numbers is too important to be left to chance.” - Robert R. Coveyou