+ Reply to Thread
Results 1 to 17 of 17

Loop through a big data table

Hybrid View

ISMI Loop through a big data table 12-23-2021, 11:38 AM
CheeseSandwich Re: Loop through a big data... 12-23-2021, 11:58 AM
CheeseSandwich Re: Loop through a big data... 12-23-2021, 12:05 PM
ISMI Re: Loop through a big data... 12-23-2021, 01:35 PM
Sintek Re: Loop through a big data... 12-23-2021, 01:59 PM
ISMI Re: Loop through a big data... 12-23-2021, 02:17 PM
Sintek Re: Loop through a big data... 12-23-2021, 02:32 PM
Bo_Ry Re: Loop through a big data... 12-23-2021, 02:40 PM
ISMI Re: Loop through a big data... 12-24-2021, 03:35 AM
ISMI Re: Loop through a big data... 12-23-2021, 03:14 PM
Sintek Re: Loop through a big data... 12-23-2021, 03:19 PM
ISMI Re: Loop through a big data... 12-23-2021, 03:27 PM
Sintek Re: Loop through a big data... 12-23-2021, 03:44 PM
ISMI Re: Loop through a big data... 12-24-2021, 03:39 AM
Sintek Re: Loop through a big data... 12-24-2021, 04:17 AM
ISMI Re: Loop through a big data... 12-24-2021, 06:11 AM
Sintek Re: Loop through a big data... 12-24-2021, 07:37 AM
  1. #1
    Forum Contributor
    Join Date
    12-24-2016
    Location
    London
    MS-Off Ver
    2013
    Posts
    153

    Loop through a big data table

    Hello gurus again,

    I have one question regarding looping through the big data table. What will be the fastest method to put certain value (row3) in certain time interval (rows 1 and 2)? Time axes is on column E. Thing is that I tried Do While loop, and in case of 10000 rows and 100 columns It tooks few minutes to calculate. File example in attachment. Appriciated for your help like always.
    Attached Files Attached Files

  2. #2
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2503
    Posts
    1,485

    Re: Loop through a big data table

    There will be a faster way but thought I would share what I had created in case it gets others creative juices flowing:

    Sub test()
        Dim rCell As Range, lkpVal
        Dim lwrVal As Long, uprVal As Long
        Dim WriteVal As Double
        
        For Each rCell In Range("A6:D21").Cells
            lkpVal = Range("E" & rCell.Row)
            lwrVal = Cells(1, rCell.Column)
            uprVal = Cells(2, rCell.Column)
            WriteVal = Cells(3, rCell.Column)
            
            If lkpVal >= lwrVal And lkpVal <= uprVal Then
                rCell.Value = WriteVal
            End If
        Next rCell
    End Sub

  3. #3
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2503
    Posts
    1,485

    Re: Loop through a big data table

    May be a little faster if we don't declare the variables unless we need to:

    Sub test()
        Dim rCell As Range, lkpVal
        Dim lwrVal As Long, uprVal As Long
        Dim WriteVal As Double, c As Long, r As Long
        
        For Each rCell In Range("A6:D10209").Cells
            If rCell.Row <> r Then
                lkpVal = Range("E" & rCell.Row)
            End If
            
            If rCell.Column <> c Then
                lwrVal = Cells(1, rCell.Column)
                uprVal = Cells(2, rCell.Column)
                WriteVal = Cells(3, rCell.Column)
            End If
            
            If lkpVal >= lwrVal And lkpVal <= uprVal Then
                rCell.Value = WriteVal
            End If
            
            c = rCell.Column
            r = rCell.Row
        Next rCell
    End Sub

  4. #4
    Forum Contributor
    Join Date
    12-24-2016
    Location
    London
    MS-Off Ver
    2013
    Posts
    153

    Re: Loop through a big data table

    Hello, it works but also took some time (few minutes for 56000 rows and 50 columns).

    What if we will use offset function: so for each column jump directly to start cell eg A8735 (skip all previous rows) and to insert value until until A8740, then jump to column B and so on...? what you think?

  5. #5
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    O365 V2408
    Posts
    15,155

    Re: Loop through a big data table

    Pls supply a sample with a bigger data set i.e 1000 rows | 20 cols
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  6. #6
    Forum Contributor
    Join Date
    12-24-2016
    Location
    London
    MS-Off Ver
    2013
    Posts
    153

    Re: Loop through a big data table

    Hello my friend,
    It is done, look in attached file. Time in column U
    Attached Files Attached Files

  7. #7
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    O365 V2408
    Posts
    15,155

    Re: Loop through a big data table

    For this to work...Put a Header in Column U

    Sub J3v16()
    Dim Data, Temp, X1, X2, i As Long, ii As Long
    Data = Cells(1).CurrentRegion: ReDim Temp(1 To UBound(Data, 1), 1 To UBound(Data, 2))
    For i = 1 To UBound(Data, 2) - 1
        X1 = Application.Match(Data(1, i), Application.Index(Data, , UBound(Data, 2)), 0)
        X2 = Application.Match(Data(2, i), Application.Index(Data, , UBound(Data, 2)), 0)
        For ii = X1 - 5 To X2 - 5: Temp(ii, i) = Data(3, i): Next ii
    Next i
    Range("A6").Resize(UBound(Data, 1), UBound(Data, 2) - 1) = Temp
    End Sub

  8. #8
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,223

    Re: Loop through a big data table

    Please try

    PHP Code: 
    Sub noLoop()
    Dim r&, c&, tm$, st$, en$, va$
    With [a1].CurrentRegion
        r 
    = .Rows.Count 5
        c 
    = .Columns.Count 1
        tm 
    = .Columns(.Columns.Count).Offset(5).Resize(r).Address
        st 
    = .Rows(1).Resize(, c).Address
        en 
    = .Rows(2).Resize(, c).Address
        va 
    = .Rows(3).Resize(, c).Address
        
    .Offset(5).Resize(rc).Value Evaluate(Replace("IF((#>=" st ")*(#<=" en ")," va ","""")""#"tm))
    End With
    End Sub 
    Attached Files Attached Files
    Last edited by Bo_Ry; 12-23-2021 at 02:42 PM.

  9. #9
    Forum Contributor
    Join Date
    12-24-2016
    Location
    London
    MS-Off Ver
    2013
    Posts
    153

    Re: Loop through a big data table

    Hello My friend,

    I have then 2 other question, is it possible to solve 2 issues with your quick method:
    1) in column LN i need to put time values from 0 to defined parameter (in example file = 57311 rows). With simple increment it tooks a lot of time.
    2) i need to find SUM for each row (from 6 to 57311, from column A to LM) and put resulting value in column LP. With simple increment it tooks a lot of time.

    Starting column always A, but end column can vary. Would be nice to have some king of automatic search.

    Thx a lot for support!
    Attached Files Attached Files

  10. #10
    Forum Contributor
    Join Date
    12-24-2016
    Location
    London
    MS-Off Ver
    2013
    Posts
    153

    Re: Loop through a big data table

    Sintek, your method works, but table 57000 rows * 325 columns it tooks about 4-5 min
    Bo_Ry: you method works also and the fastest one, for same table it tooks approx 20-30 sec.

    Thank you to both of you, you guys are crazy and i don't know how you do that, amazing job. Greetings and all the best

  11. #11
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    O365 V2408
    Posts
    15,155

    Re: Loop through a big data table

    4-5 min...that is forever in coding terms lol...

  12. #12
    Forum Contributor
    Join Date
    12-24-2016
    Location
    London
    MS-Off Ver
    2013
    Posts
    153

    Re: Loop through a big data table

    yea, for small table it is very fast, but then table is huge a lot of calcs in background. My laptop is intel i7 with 16 Gb RAM, not Pentium 1 so should ok for this kind of calcs

  13. #13
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    O365 V2408
    Posts
    15,155

    Re: Loop through a big data table

    Quick Question...Has Col U got numbers from 0 to X in increments of 1 in order...

  14. #14
    Forum Contributor
    Join Date
    12-24-2016
    Location
    London
    MS-Off Ver
    2013
    Posts
    153

    Re: Loop through a big data table

    Quote Originally Posted by sintek View Post
    Quick Question...Has Col U got numbers from 0 to X in increments of 1 in order...
    Hello my friend,
    Yes in column U (time) i have minutes 0, 1, 2, ..., N (time horizont is always defined parameter)

  15. #15
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    O365 V2408
    Posts
    15,155

    Re: Loop through a big data table

    i need to find SUM for each row (from 6 to 57311, from column A to LM) and put resulting value in column LP.
    Sub J3v16()
    Dim Mx As Long, i As Long, lc As Long, St As Long, Fn As Long
    lc = Cells(1, Columns.Count).End(xlToLeft).Column
    Mx = Application.Max(Range(Cells(1, 1), Cells(2, lc)))
    'Rows(6 & ":" & Mx).ClearContents
    With Cells(6, lc + 1).Resize(Mx + 1)
        .Value = Evaluate("=Row(" & .Address & ")-6")
    End With
    For i = 1 To lc
        St = Cells(1, i).Value: Fn = Cells(2, i).Value
        Cells(St + 6, i).Resize(Fn - St + 1).Value = Cells(3, i)
    Next i
    Cells(6, lc + 3).Resize(Mx + 1).FormulaR1C1 = "=SUM(RC[-" & lc + 2 & "]:RC[-3])"
    End Sub
    Attached Files Attached Files
    Last edited by Sintek; 12-24-2021 at 04:58 AM.

  16. #16
    Forum Contributor
    Join Date
    12-24-2016
    Location
    London
    MS-Off Ver
    2013
    Posts
    153

    Re: Loop through a big data table

    it works, 1 sec, my friend shake your hand again!!!!

  17. #17
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    O365 V2408
    Posts
    15,155

    Re: Loop through a big data table

    it works, 1 sec
    Now that's better than 4 mins lol

+ 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. Loop through Sheets to add new data to last row of Table - VBA
    By Jlopez21887 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-10-2020, 01:42 PM
  2. [SOLVED] Loop through Rows in a table and add data to a Chart
    By jgoodz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-27-2016, 11:50 PM
  3. [SOLVED] Auto email loop with formatted table data breaking on second loop VBA
    By Who_else in forum Excel General
    Replies: 6
    Last Post: 03-24-2016, 06:22 AM
  4. For Each loop for data labels in a pivot table
    By Phixer in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-12-2015, 11:51 AM
  5. [SOLVED] Loop through all worksheets and format data found as table
    By jvr2 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-02-2014, 09:52 PM
  6. Script loop - get data from html table
    By Rawland Hustle in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 10-02-2012, 02:32 PM
  7. enter data from a table into a sheet, loop help required
    By bl2k6 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-17-2011, 11:57 PM

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