Results 1 to 20 of 22

Thread: Improve Efficiency of VBA Code

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #9
    Thank you everyone for your support
    I am attaching the new file Please have a look at the example in "main workbook" to see what I mean.
    Sub test()
        Dim ws As Worksheet, rng As Range, cl As Range, lr As Long, c As Long
        Const fRow As Long = 6
        Const sRow As Long = 8
        
        Application.ScreenUpdating = False
            Set ws = ThisWorkbook.Worksheets("main workbook")
            lr = ws.Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
            Set rng = ws.Rows(fRow).SpecialCells(xlCellTypeFormulas)
            
            For Each cl In rng
                c = cl.Column
                ws.Cells(fRow, c).Copy: ws.Cells(sRow, c).PasteSpecial Paste:=xlPasteFormulas
                
                With ws.Range(ws.Cells(sRow, c), ws.Cells(lr, c))
                    .Formula = ws.Cells(sRow, c).Formula
                   .Value = .Value
                End With
            Next cl
            Application.CutCopyMode = False
        Application.ScreenUpdating = True
    End Sub

    Any help would be greatly appreciated!!! - thanks in advance...
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •