Which is the Fastest VBA Method For Reading Tables?

Поділитися
Вставка
  • Опубліковано 10 лют 2025

КОМЕНТАРІ • 103

  • @Excelmacromastery
    @Excelmacromastery  3 роки тому +12

    Hope you enjoy this video. Let me know in the comments which version you use.

    • @MahendraTita
      @MahendraTita 3 роки тому

      Excel 2010

    • @alexeiofp
      @alexeiofp 3 роки тому

      Excel 2010 and 2019

    • @todddupcak5336
      @todddupcak5336 3 роки тому

      Arrays are the way to go especially if you want to edit data in any of the rows/columns. Next video should show how changing values in an array is faster than editing values in a range.

    • @MahendraTita
      @MahendraTita 3 роки тому

      Array give all data in one dataset and you can play with dataset, it's fastest way of data capturing and do work, Thank you again for your video. Mr Mahendra K Tita from India.

    • @konstantinevseyenko9312
      @konstantinevseyenko9312 3 роки тому

      Use assignment DataBodyRange to Range variable and For Each loop. But really impressed how array is faster and will switch to use it more often.

  • @rubenmunozverdu7528
    @rubenmunozverdu7528 3 роки тому +4

    Ok, I saw the full video. I was going to pause it and comment "why not reading it into an array at once", haha! Nice timer class!

  • @logic3686
    @logic3686 3 роки тому +6

    Your videos sped up my programs quite a bit. I wished I found you a lot sooner in my progression of learning VBA.
    I first put the table into an array then put the array into a Dictionary. I use this method 99% of the time if I'm looping through another set of data for comparing. I have created subroutines to create the Dictionaries that keeps my code neat. I'll pass the Dictionary subroutine parameters such as the key, item, criteria, transposed, if columns should be summed, Include header row of Array, avoid blanks, add to or erase passed Dictionary.
    The Xaxis1strecord one or more concatenated columns with a vbtab delimiter added between the values and stored as a string recorded for the key in the Dictionary.
    The Xaxis2ndrecord is also one or more columns but stored into an array recorded as the item in the Dictionary.
    Sub Arr2Dict(Dict, arr, Xaxis1strecord, Xaxis2ndrecord, Optional MultiCrit As String, Optional yaxisDim As Long, Optional ColSumArr As String, _
    Optional HeaderArrRow As Boolean, Optional NoRemBlanks As Boolean, Optional NoErase As Boolean)

  • @Mr-J...
    @Mr-J... 2 роки тому +2

    It's years since I programmed in vba but am enjoying your videos in a nostalgic sense.
    I remember a sheet I had that took over 20 minutes to calculate using ranges. I converted to arrays and it to less than a minute.
    I seem to remember setting the range via a shortcut method, something like rg = [tbName] though.

  • @MahendraTita
    @MahendraTita 3 роки тому +1

    I used array method, learned from your tutorial. Thank you for sharing
    Mahendra K Tita from India

  • @free3690
    @free3690 3 роки тому +2

    I always use the first one. I feel like i need to know which cell the for is working on. It’s time to switch to arrays! Thanks for the video, it clearly shows the difference with live data.

  • @WazirSamsair
    @WazirSamsair 2 місяці тому

    Although I don't deal with large stack data, I have been revamping my codes using arrays.
    And this is based on your clock time videos I seen to date.
    I am not a programmer and my codes are pretty basic (lacks efficiency), so your advice helped me a lot when I see update lagging.

  • @sunnder0
    @sunnder0 3 роки тому +2

    I see a lot of comments touting Python being a better data manipulator than VBA. Would love to see a similar video to this but also comparing other methods external to VBA.

  • @777rag777
    @777rag777 3 роки тому +2

    Hi Paul, your website & videos are my go to...just sooooo great!!! I always use arrays to read data from my worksheet (ranges & tables), and this definitely confirms it is the best way. Simply awesome 👍👍!!!

  • @keithturner2889
    @keithturner2889 3 роки тому +1

    Before I started watching Paul’s videos I read data from the worksheet now I always arrays

  • @ChrisM541
    @ChrisM541 3 роки тому +1

    Wonderful set of tests showing just how critical it is to 'Know Your Optimal VBA Methods' - that is, of course, if you place any value on optimal user experience!
    It's the price we pay for the relentless march of programming language abstraction...for everything except assembly language, we've lost control over the form of that final machine code executable...!!!

  • @TheJoeFletch
    @TheJoeFletch Рік тому

    I have implemented using the Array methodology to retrieve data and it has decreased my code execution time significantly (just like it is displayed in the video). I highly suggest using this method!

  • @mdbm500
    @mdbm500 2 роки тому

    Thanks. I use arrays in my work, but I didn't even think about such subtleties. now my code will be less stupid.

  • @TravisFX
    @TravisFX 3 роки тому

    For me it's about what type of code looks and reads better. Rather than saving 6 or 700 milliseconds! But it's good to know these things for sure

  • @bayurukmanajati1224
    @bayurukmanajati1224 3 роки тому +1

    Thank you for the video! This is very helpful. But I think I should just go straight to your website for further reading as usual.

  • @rajubalasubramaniyam9002
    @rajubalasubramaniyam9002 Рік тому

    Nice one though hey am a beginner and venturing into automating a tool via vba excel ;
    Requirements would be to loop in thru table and compare each row value and column for either 6points ascending or 10 pts above average

  • @jamesmann7411
    @jamesmann7411 3 роки тому

    Hi Paul thanks for the video. Just started learning VBA. As my knowledge improves I'll head over to your arrays playlist. I'm convinced.

  • @akshayc7152
    @akshayc7152 3 роки тому +5

    Hello Paul, thank you for this video..u r truely awesome..can you please make some detailed videos to work on table data using vba and combine the same with power query

  • @johnwayne8059
    @johnwayne8059 3 роки тому

    Pretty good sample for the speed of the different reading types!👍👍👍🤟😎

  • @bogdanexit1
    @bogdanexit1 3 роки тому +2

    Nice work
    Now i use 99% only arrays and dictionary in all my code thanks for sharing Paul. maybe can you make a future video how to place and dump colors in arrays

    • @suvadipkundu152
      @suvadipkundu152 3 роки тому

      You can write the color ( or other format property enumeration values) as array elements and read them back.. not very efficient I would think but better than reading thru' cells/range, copying them any day. I would think that the variance would start showing as the range size becomes bigger.

  • @big1975E
    @big1975E 3 роки тому +3

    Great video! I definitely use arrays and if I have to tables to compare to each other I’ll put one table in a dictionary and one in an array comparing the array to the dictionary.

    • @Excelmacromastery
      @Excelmacromastery  3 роки тому +1

      Thanks for the feedback😀

    • @big1975E
      @big1975E 3 роки тому +1

      @@Excelmacromastery thank you for doing these videos and sharing your knowledge. I use arrays and dictionaries because of what I’ve learned from watching them!

  • @timburraston8063
    @timburraston8063 3 роки тому +2

    Hi Paul, another excellent video. I have only recently realised the power of arrays for this sort of processing and it's transformed many tasks I do. One small question on your code for the array solution: might assigning the lower and upper array boundaries to variables before the loop further improve efficiency of this code?
    Thanks and keep up the great work.
    Tim

  • @gczz
    @gczz 3 роки тому

    Once I had to develop a code to get one Excel sheet with lots of info into another one, but in a tabular format. The original one had blocks of information, i.e., dates in the columns, values in the rows, but each category was spaced out from the other with blank cells, and then it proceeded to repeat the date columns and the value rows for the other category. At first I started with a code that would get each cell of the "table" and put it into tabular format in another table. I did some tests and estimated around 1 hour to run everything. After some thoughtful consideration, I realized I basically needed to copy the whole block and transpose it to achieve the tabular format for each category. So I did it using an array for each block. It took, and I kid you not, less than 5 seconds to go through everything.

    • @Excelmacromastery
      @Excelmacromastery  3 роки тому

      That's an amazing difference in speed. Thanks for sharing.

  • @alexeiofp
    @alexeiofp 3 роки тому

    thanks master for this video readind tables, i was expected tis kind material, thanks you from Santiago de Chile.

  • @jom3211
    @jom3211 3 роки тому +1

    Array method, as always great video. Thanks Sir

  • @niczoom
    @niczoom 2 роки тому

    Always well presented and great value!

  • @marksholcomb
    @marksholcomb 3 роки тому

    Great video! In Memory best unless you have very big databases… limit on excel ( I forget the max size) but i hit the limit often in my work.

  • @stevennye2441
    @stevennye2441 3 роки тому +1

    great work!

  • @dd1965
    @dd1965 3 роки тому

    array and dictionary are a good combo

  • @postventatewis9968
    @postventatewis9968 2 роки тому

    Great!!!! Thanks for share. What about the faster speed of calculus iterations?

  • @MiguelSeijas-f6z
    @MiguelSeijas-f6z 6 місяців тому

    Muchas gracias. Este tutorial está súper.

  • @jadermsantos
    @jadermsantos 3 роки тому

    Wonderful video!

  • @tigranhayrapetyan8357
    @tigranhayrapetyan8357 3 роки тому +1

    Paul, I've known about arrays from you, so thank you very much! Can you please make video about the fastest method of editing data? For example replacing characters

    • @suvadipkundu152
      @suvadipkundu152 3 роки тому

      This is what I do... Array+instr to get to what I am looking for in each row, tag 'em and use string functions (left, right and Len) to replace sub string , store in array and paste when done.
      Do not know if it will be fastest though :)

  • @suvadipkundu152
    @suvadipkundu152 3 роки тому

    Paul,
    As always thanks a bunch for a nice vote of confidence to arrays 😊..
    A bit of a tangent of a query on arrays.. my biggest grouse with them has been the inability use them as a range in a lookup... One of my colleagues demo-ed that you can use a one dimensional one in lieu of a range but no such luck with 2d arrays... Would you have a suggestion the same?
    Bests from a big fan 😁😁
    Cheers
    Suvadip

  • @emililie2244
    @emililie2244 3 роки тому

    Thanks. The myTimer object is interesting. How is it done?

  • @shaikhmohammadfaizala3335
    @shaikhmohammadfaizala3335 3 роки тому

    You are genius boss

  • @cringerfringe2285
    @cringerfringe2285 3 роки тому +2

    Thanks for the video! I don't see the source code link. Does that source code include the class module for your timer? I would love to use it.

    • @vbaclasses3553
      @vbaclasses3553 3 роки тому +2

      Im sure Paul will update the link. There was actually another video where he share the timer, but it did not have the estarttime and elasttime enums. I tried to locate it but unfortunately no luck, sorry.

    • @Excelmacromastery
      @Excelmacromastery  3 роки тому +2

      I will add the link shortly😀

  • @tomharrington1453
    @tomharrington1453 3 роки тому

    This is really good.

  • @vppoole
    @vppoole 3 роки тому +1

    I love arrays and find them to be transforming the way I code, but what's the row limit of an array variable, though?
    Isn't it somewhere around 60k rows if you're using Excel 2016?

    • @suvadipkundu152
      @suvadipkundu152 3 роки тому

      Wow interesting, will check this... I somehow think not (unless ofcourse you have a large number of columns in the mix as well)... Will confirm

  • @Trucpq
    @Trucpq 3 роки тому

    Hi. How about reading data to an array then copy direct the whole array to a range?

  • @mrkjmnz
    @mrkjmnz 3 роки тому

    Does the speed the same if its not in table?

  • @Rice0987
    @Rice0987 3 роки тому

    I know, arrays are ruling, but it a bit hard for me to use them. :)
    I prefer to use range for and sometimes each.
    THANK YOU, SIR!

    • @Excelmacromastery
      @Excelmacromastery  3 роки тому +1

      If you haven't a large amount of data then ranges are fine.

    • @Rice0987
      @Rice0987 3 роки тому

      @@Excelmacromastery I'm on approach to use VBA with big data. So i need more effective instruments for this.

  • @luisflavioaquino
    @luisflavioaquino 3 роки тому

    Great video! Could you please make a video comparing vlookup formula in VBA to other methods? For example using Arrays vs Vlookup.

  • @ksmemon1
    @ksmemon1 3 роки тому +1

    In Arrays How can we get values with Columns Names? Is there anything like Ado Queries to Select Specific Column's Value with Criteria

    • @todddupcak5336
      @todddupcak5336 3 роки тому

      arr = shSales.ListObjects("tbSales").Range.Value will put the headers into the same array. You can then do a for loop to go through the columns then the rows. Alternatively, you can create a separate array for the column names by doing arrH = shSales.ListObjects("tbSales").HeaderRowRange.Value. LBound(arr,1) and UBound(arr,1) will get you the min/max rows. LBound(arr,2) and UBound(arr,2) will get you the min/max columns.

    • @Excelmacromastery
      @Excelmacromastery  3 роки тому +1

      There isn't anything like this for arrays. The disadvantage of arrays in vba is that they have very little functionality. That's why I created this class ua-cam.com/video/ZYxa-Q-nSX0/v-deo.html

    • @ksmemon1
      @ksmemon1 3 роки тому

      @@Excelmacromastery Yes I have Already Watch it multiple times and and used your 2d Array Class it is very Brilliant Work. 👍

  • @wulp1191
    @wulp1191 3 роки тому +1

    Great as usual but no link to file this time...

  • @wayneedmondson1065
    @wayneedmondson1065 3 роки тому

    Thanks Paul! Arrays are the way to go. Thanks for demonstrating and comparing methods.. very instructive. Thumbs up!!

  • @Jocedu06
    @Jocedu06 3 роки тому

    Amazing

  • @alializadeh8195
    @alializadeh8195 3 роки тому

    Thanx

  • @zzota
    @zzota 3 роки тому

    I used to use For n = 1 to whatever. Now I'll be using arrays 🙂I was always worried that arrays would clog up the memory. Would you use Set arr = Nothing, or will it clear itself?

    • @Excelmacromastery
      @Excelmacromastery  3 роки тому +1

      You only use "Set = Nothing" for objects. The array will automatically be deleted when the array goes out of scope or you assign the variable to something else.

    • @jurajjakubec8930
      @jurajjakubec8930 3 роки тому

      @@Excelmacromastery ArrayName = Empty

  • @fredb6187
    @fredb6187 3 роки тому

    I use array to process data for many years. It's the most efficient way...
    1) Load All Data in one read
    2) Process data with a 2D array (even you have one columns)
    3) Paste the data in the sheet in one write
    With this example ( 50000x3), it take 0.25 sec for me (it depend to your computer) with pasting of the data... (30ms without the pasting)
    for exemple:
    Sub ReadTable()
    Dim myTimer As Double
    '---
    myTimer = Timer
    Call forTable
    '---
    Debug.Print Timer - myTimer
    End Sub
    Sub forTable()
    '--- Variable
    Dim rng_R As Range
    Dim vnt_Data As Variant
    Dim temp As Variant
    Dim i As Long
    Dim j As Long
    '--- Initialisation
    Set rng_R = ThisWorkbook.Worksheets(1).Range("a1")
    vnt_Data = Range(rng_R, rng_R.End(xlDown).Offset(0, 2)).Value
    '--- Loop
    For i = 1 To UBound(vnt_Data, 1)
    For j = 1 To UBound(vnt_Data, 2)
    temp = vnt_Data(i, j)
    Next j
    Next i
    '--- Paste new Data
    Range(rng_R, rng_R.End(xlDown).Offset(0, 2)).Value = vnt_Data
    End Sub

  • @luismesainc
    @luismesainc 3 роки тому

    Excuse me, I don't understand what is "shSales". Please, could you please explain? You are the best!

  • @positifnegatifofficial
    @positifnegatifofficial 2 роки тому

    How file Excel vba form activation in file?

  • @pbs36
    @pbs36 3 роки тому

    The performance of arrays is great buy in the real world data is not always nice and clean.
    The first time I tried loading a range into an array, the code would abort with no message, as I had never seen VBA do. Debugging line by line revealed the problem was in the line where the array was being assigned the range. A cell with a formula error was making it crash.

  • @m_marcamo
    @m_marcamo 3 роки тому

    Oh noooo. I must rewrite my "listrowfor" method code by a new "array" code. Thank you Paul.

    • @TravisFX
      @TravisFX 3 роки тому

      Yes because why "waste" 800 milliseconds of precious time ! 🤣

  • @kunjeshparikh6845
    @kunjeshparikh6845 2 роки тому

    Why is it that Excel takes different processing time for the same macro for the same dataset each time we run it? I have a macro that takes on average 3 minutes to run, but sometimes it even takes 5-6 minutes to run.

    • @Excelmacromastery
      @Excelmacromastery  2 роки тому

      If you have other apps running they can alow your machine down. That said I wouldn't expect such a discrepancy until you were running a resource hungry app

  • @billcouch9850
    @billcouch9850 3 роки тому

    I don’t understand what this code does. What is its purpose?

  • @kevincoleman7164
    @kevincoleman7164 3 роки тому

    I didn't see the link to download the source in the description

  • @wesber80
    @wesber80 3 роки тому

    Amazing... Bessings

  • @Fab2Mc
    @Fab2Mc 3 роки тому

    Super

  • @kolavithonduraski5031
    @kolavithonduraski5031 3 роки тому

    what is the main reason the array is faster 🤔❓ Is it the definition of the array (arr = shSales ....) or is it the reading out of the array with the for loop ?
    That would be as well interesting for the other cases 🤭
    ------
    i for myself use arrays, but to define it... i do a oldschool loop to fill my array with data. Not that elegant like you 😅😅😅
    Thanks 👍👍👍

    • @Excelmacromastery
      @Excelmacromastery  3 роки тому +1

      It's both. Assigning the array is fast as is read through the array. The array is simply a group of adjacent memory values.

  • @abdurrehman5038
    @abdurrehman5038 3 роки тому

    not downloading the file by given link.

  • @oleksijm
    @oleksijm 3 роки тому +3

    as expected, arrays rule.

  • @TheSardOz
    @TheSardOz 3 роки тому

    Hi Paul, do you do consulting? Can I contact you by email?

    • @Excelmacromastery
      @Excelmacromastery  3 роки тому +1

      Sorry, I'm not available for consultation work at this time.

  • @bekirboragozukizil
    @bekirboragozukizil 3 роки тому

    is the workbook missing?

  • @didzisstalidzans5232
    @didzisstalidzans5232 3 роки тому

    👍

  • @rlh7210
    @rlh7210 3 роки тому

    To me it looked like you read only the first column of the table, not the complete table.

  • @johnanonanonanon3567
    @johnanonanonanon3567 Рік тому

    It's too fast. I have to slow down the video to keep up.

  • @manuelaleixandre7993
    @manuelaleixandre7993 2 роки тому

    LInk dont work..... sorry!

  • @shaikhmohammadfaizala3335
    @shaikhmohammadfaizala3335 Рік тому

    👍