+ Reply to Thread
Results 1 to 23 of 23

Optimize code

Hybrid View

DarkKnightLupo Optimize code 02-05-2014, 05:49 AM
teh.format Re: Optimize code 02-05-2014, 06:18 AM
Izandol Re: Optimize code 02-05-2014, 06:22 AM
DarkKnightLupo Re: Optimize code 02-05-2014, 06:27 AM
Izandol Re: Optimize code 02-05-2014, 06:40 AM
DarkKnightLupo Re: Optimize code 02-05-2014, 07:24 AM
Izandol Re: Optimize code 02-05-2014, 07:48 AM
DarkKnightLupo Re: Optimize code 02-05-2014, 08:34 AM
DarkKnightLupo Re: Optimize code 02-05-2014, 08:31 AM
Izandol Re: Optimize code 02-05-2014, 08:52 AM
DarkKnightLupo Re: Optimize code 02-05-2014, 10:14 AM
Izandol Re: Optimize code 02-05-2014, 10:37 AM
DarkKnightLupo Re: Optimize code 02-05-2014, 10:49 AM
Izandol Re: Optimize code 02-05-2014, 11:24 AM
DarkKnightLupo Re: Optimize code 02-05-2014, 12:09 PM
Izandol Re: Optimize code 02-05-2014, 12:11 PM
DarkKnightLupo Re: Optimize code 02-05-2014, 12:17 PM
Izandol Re: Optimize code 02-05-2014, 12:24 PM
DarkKnightLupo Re: Optimize code 02-18-2014, 06:21 AM
Izandol Re: Optimize code 02-18-2014, 12:25 PM
DarkKnightLupo Re: Optimize code 02-19-2014, 05:28 AM
Izandol Re: Optimize code 02-19-2014, 05:43 AM
DarkKnightLupo Re: Optimize code 02-19-2014, 08:58 AM
  1. #1
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Optimize code

    If file is saved as .xlsm then yes you must change this. If it is file with code we may use better syntax:
    Sub ImportPCB()
    '
    ' ImportPCB Macro
    '
    
    '
       Const csPATH                    As String = "C:\Users\allaer81\Documents\Dimitri04Feb2014\"
       
       ' change this number as required
       Const NUMBER_OF_FILES           As Long = 11
       
       Dim wb                          As Workbook
       Dim n                           As Long
    
       Application.ScreenUpdating = False
    
       Set wb = Workbooks.Open(Filename:=csPATH & "PCBS01.CSV")
       wb.Sheets(1).Columns("A:B").Copy
       ThisWorkbook.ActiveSheet.Range("A1").PasteSpecial Paste:=xlPasteValues, _
                                                                           Operation:=xlNone, SkipBlanks:=False, Transpose:=False
       Application.CutCopyMode = False
       wb.Close False
    
       For n = 2 To NUMBER_OF_FILES
    
          Set wb = Workbooks.Open(Filename:=csPATH & "PCBS" & Format(n, "00") & ".CSV")
          wb.Sheets(1).Columns("B:B").Copy Destination:=ThisWorkbook.ActiveSheet.Cells(1, n + 1)
          wb.Close False
       Next n
    
       Cells.NumberFormat = "0.00"
    
       Range("B2").Value = "PCBS01"
       Range("B2").AutoFill Destination:=Range("B2:L2"), Type:=xlFillDefault
       Cells(2, NUMBER_OF_FILES + 2).Resize(, 3).Value = Array("Average", "STDEV", "%")
       Cells(4, NUMBER_OF_FILES + 2).FormulaR1C1 = "=AVERAGE(RC[-11]:RC[-1])"
       Cells(4, NUMBER_OF_FILES + 3).FormulaR1C1 = "=STDEV(RC[-12]:RC[-2])"
       With Cells(4, NUMBER_OF_FILES + 4)
          .FormulaR1C1 = "=RC[-1]/RC[-2]"
          .NumberFormat = "0.0000%"
       End With
       Cells(4, NUMBER_OF_FILES + 2).Resize(, 3).AutoFill Destination:=Cells(4, NUMBER_OF_FILES + 2).Resize(200, 3)
    
    
       Cells.EntireColumn.AutoFit
       
       Application.ScreenUpdating = True
    
    End Sub
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  2. #2
    Registered User
    Join Date
    02-05-2014
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Optimize code

    Ok one nore esthetical question,

    Range("B2").Value = "PCBS01"
    Range("B2").AutoFill Destination:=Range("B2:L2"), Type:=xlFillDefault

    L2 is for 11 files, but can you adapt it to the number you modify, for example 27 zithout counting everytime the Range ?

    it is not that important!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Optimize a slow code...
    By benoitly in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-02-2013, 01:44 PM
  2. Optimize code
    By miso.dca in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-08-2011, 03:35 PM
  3. Optimize Alphabetizing VBA Code
    By NewExcelUser in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-29-2010, 11:51 PM
  4. How can I optimize/simplify that code ?
    By Grek in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-08-2010, 03:38 PM
  5. Optimize VBA code
    By doodlebug in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-22-2007, 07:53 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1