Add mutiple worksheet in new workbook and copy & paste data value and format from another worksheet

arunsjain

Board Regular
Joined
Apr 29, 2016
Messages
130
Office Version
  1. 365
Platform
  1. Windows
Hi,

Following code is adding workbook (wb2) and add worksheet subsequently. Copy data from Wb1 and paste in Wb2 in added new worksheet but not able to paste format of wb1.

Please make changes in following code to simplify it as well.

Highly appreciate your help.


Code:
Sub Summary()
    
    Dim x As Integer
    Dim lRow
    Dim wb1 As Workbook
    Dim wb2 As Workbook
    
    Set wb1 = ActiveWorkbook
    Set wb2 = Application.Workbooks.Add
    
    lRow = wb1.Worksheets("List").Cells(Rows.Count, "A").End(xlUp).Row
    
     Application.ScreenUpdating = False
        
      For x = 2 To lRow
        
        wb1.Worksheets("Calculator").Range("C2").Value = wb1.Worksheets("List").Cells(x, "C").Value
        wb1.Worksheets("Calculator").Range("C3").Value = wb1.Worksheets("List").Cells(x, "D").Value
        wb1.Worksheets("Calculator").Range("C4").Value = wb1.Worksheets("List").Cells(x, "E").Value
        wb1.Worksheets("Calculator").Range("C5").Value = wb1.Worksheets("List").Cells(x, "F").Value
        wb1.Worksheets("Calculator").Range("C6").Value = wb1.Worksheets("List").Cells(x, "G").Value
        wb1.Worksheets("Calculator").Range("C7").Value = wb1.Worksheets("List").Cells(x, "H").Value
        wb1.Worksheets("Calculator").Range("C8").Value = wb1.Worksheets("List").Cells(x, "I").Value
        wb1.Worksheets("Calculator").Range("C9").Value = wb1.Worksheets("List").Cells(x, "J").Value
        wb1.Worksheets("Calculator").Range("C10").Value = wb1.Worksheets("List").Cells(x, "K").Value
                                                     
      
        If wb1.Worksheets("Calculator").Range("C5").Value <> 0 Then
      
             wb1.Worksheets("Calculator").Range("A1:W45").Copy
             wb2.Worksheets.Add
              
             With wb2.ActiveSheet
            .PasteSpecial xlPasteValuesAndNumberFormats
            End With
        
        Else
            GoTo nextiteration
        End If
                
nextiteration:
                            
    Next x
     
    Application.CutCopyMode = False
     
    Application.ScreenUpdating = True
End Sub

Kind Regards
Arun
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Forum statistics

Threads
1,223,710
Messages
6,174,019
Members
452,542
Latest member
Bricklin

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