Results 1 to 22 of 22

Copy columns from sheet 1 to sheet 2 using column heading as criteria using VBA

Threaded View

  1. #16
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    Re: Copy columns from sheet 1 to sheet 2 using column heading as criteria using VBA

    Quote Originally Posted by Jacc View Post
    Apo's code is very cool and crazy fast! At least one million times faster than the rest of us, can that be right? I'm not sure I trust this timer function for such low numbers.
    Hi Jacc,
    . I am going a bit over both my competence and the capabilities of my 10 year old worn out slow computer here probably:
    – I may have over looked something - you could probably do the following better:
    . Here are Some speed tests based on an old Thread of mine – see around post # 12 here:
    http://www.mrexcel.com/forum/excel-q...looping-2.html
    . Basically I am using both the VBA Timer and the Charley Williams Micro Timer, referenced in that Thread above, and pointed out to me by Jerry Sullivan..
    .. Here are my initial results for my old Note Book - ( ACER 4810TZG Vista XL 2007. )
    . But I should emphasize that in other Threads such as
    http://www.mrexcel.com/forum/excel-q...vlookup-9.html
    .. I have had very inconsistent results with different computers, XL versions , operating software etc. etc.

    Using Excel 2007
    VBA Timer Charley Williams Micro Timer
    Captain apo
    0.44
    0.44
    Alan SHmpfGlified
    0.54
    0.54
    Alan Full
    0.55
    0.55
    Jacc
    0.371
    0.371
    SpeedTests

    . I almost understand apo’s code - My code and apo’s are basically similar – stands to reason – These sort of codes I do are usually stolen from versions of his codes!!! Mine would be a bit slower because of unecerssary transposing - I just cannot get the hang of how the Application.Index works exactly with Arrays as it's second and third arguments )
    . Yours is new, and a nice alternative. I understand it now
    . I will look at Marc L’s later, but I am busting me Nuts just now trying to understand how or if that works - I have no idea yet!!


    . Here are the codes I am using for the speed tests:

    ' next 2 lines needed for 'Charley Williams Micro Timer Code
    Private Declare Function getFrequency Lib "kernel32" Alias "QueryPerformanceFrequency" (cyFrequency As Currency) As Long
    Private Declare Function getTickCount Lib "kernel32" Alias "QueryPerformanceCounter" (cyTickCount As Currency) As Long
    '
    Sub Timers() 'SubRoutine to call Timer Functions and Subroutines under test and display results.
     
    Dim StartMTTime As Single, StartVBATime As Single 'times inn seconds at start of a run
    Dim MTTime As Single, VBATime As Single 'Run times given from Timer Functions
    Let MTTime = 0 'Could leave this out, but good
    Let VBATime = 0 'Practice to put it in
    Dim Iteration As Long, MaxIteration As Long 'Variable used in avaraging a few runs
    Let MaxIteration = 10 'Set here the nimber of runs that you want.
        
        'First Run: timing is often longer first time so do first run without Timers
        Call CaptnApo 'First Run: timing is often longer first time so do first run without Timers
        'Call CopyColumnsAlanSHimpfGlified
        'Call CopyColumnsAlan
        'Call copycolumns_Jacc
        
        'Main Runs to obtain average times
          For Iteration = 1 To MaxIteration 'Run as many times as specified.
          Let StartMTTime = MicroTimer 'Function Code from Charley Williams
          Let StartVBATime = VBATimer 'Typical VBA Timer() Function code
        
        Application.ScreenUpdating = False
          Call CaptnApo
          'Call CopyColumnsAlanSHimpfGlified
          'Call CopyColumnsAlan
          'Call copycolumns_Jacc
        Application.ScreenUpdating = True
          Let MTTime = (MTTime + (MicroTimer - StartMTTime)) 'Total times so
          Let VBATime = (VBATime + (VBATimer - StartVBATime)) 'far.
          Next Iteration 'Go and do another run(s)
        MsgBox "Micro Timer " & (MTTime) / MaxIteration & " Seconds" & vbCr & _
               "VBA Timer " & (VBATime) / MaxIteration & " Seconds" 'Display avarage results.
    End Sub ' Timers()
    
    '
    
    
    Function VBATimer()
    'Typical VBA Timer Program
        VBATimer = Timer 'Timer is a VBA Function that gives current time in seconds
    End Function ' VBATimer()
    Function MicroTimer() As Single 'Charley Williams Micro Timer Code
     
        Dim cyTicks1 As Currency
        Static cyFrequency As Currency
        Let MicroTimer = 0
          If cyFrequency = 0 Then getFrequency cyFrequency ' get ticks/sec
          getTickCount cyTicks1 ' get ticks
          If cyFrequency Then MicroTimer = cyTicks1 / cyFrequency ' calc seconds
        
    End Function 'MicroTimer()
    '
    '
    '


    .. I will drop the 4 actual Sub codes I timed in next Post #15 because of the Thread size limitations at Excel Forum……..
    Last edited by Doc.AElstein; 07-21-2015 at 06:21 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Copy Columns to another sheet based on column heading
    By jhall488 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-05-2014, 03:46 PM
  2. [SOLVED] Auto copy contents from sheets 2 and 3 to sheet 1 if column heading contains set words
    By Thomas Andrews in forum Excel Formulas & Functions
    Replies: 20
    Last Post: 06-09-2014, 11:59 AM
  3. how to copy columns of another sheet with the column data of current sheet
    By amethystfeb in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-28-2014, 11:28 PM
  4. [SOLVED] COUNTIF with multiple criteria on several columns (different column heading)
    By rose4emi in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-20-2012, 06:41 AM
  5. [SOLVED] Search for heading in data sheet and copy range to corresponding sheet in master workbook
    By sans in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-07-2012, 10:02 AM
  6. Macro to filter based on column heading then copy and paste to new sheet
    By macattackr in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-01-2012, 05:14 PM
  7. Search for column heading and copy column onto another sheet
    By chrismann85 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-28-2008, 05: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