+ Reply to Thread
Results 1 to 2 of 2

Starting a new calculation loop when a new entry in column A is reached

Hybrid View

  1. #1
    Registered User
    Join Date
    06-22-2016
    Location
    Utrecht
    MS-Off Ver
    MS Office 2013
    Posts
    2

    Starting a new calculation loop when a new entry in column A is reached

    Hi everyone!

    I would like to ReSample intervals in order to get a continuous serie. I also put a classification number next to the continuous serie.
    I already managed to do this for 1 Name (PIET). Now I want to do the same with a second Name (HENK) in the database. For this I need the code to start a new loop, when a new name is found in the database (same as finding a '0' as top). I would like to have the new results in a new workbook with the name HENK. If possible I would like to have the results of PIET also in a new workbook with the name PIET.
    I put my excel file in the appendix.

    Current Code:
     
    Sub IntervalToSample()
        Dim Cancelled, OldStatusbar As Boolean
        Dim NOI, TI, TS, DOF, i, j, Samples, SII As Integer
        Dim Counter, Bounter As Long
        Dim Top, Base, Inc, TopI, BaseI As Double
        Dim Name As String
    
        OldStatusbar = Application.DisplayStatusBar
        
     '---------------->>> Data Definition Section <<<-----------------------
        DOF = 5
        Counter = 0
        Bounter = 0
        SII = 0
        Name = Sheets("Data").Cells(DOF + 1, 1)
        Top = Sheets("Data").Cells(DOF + 1, 2)
        Inc = Sheets("Samples").Cells(1, 6)
        Sheets("Data").Select
        Range("A1").End(xlDown).Select
        TI = ActiveCell.Row - DOF
        Base = Sheets("Data").Cells(ActiveCell.Row, 3)
        TS = Int((Base - Top) / Inc) + 2
        
        Sheets("Samples").Cells(2, 6) = Name
        Sheets("Samples").Cells(3, 6) = Top
        Sheets("Samples").Cells(4, 6) = Base
        Sheets("Samples").Cells(5, 6) = TI
        Sheets("Samples").Cells(6, 6) = TS
            
        Application.ScreenUpdating = False
        Application.StatusBar = True
        
     '---------------->>> Begin of calculation loop. Everything after this line is meant for the calculation. <<<-----------------------
        If Not Cancelled Then
           
          For i = 1 To TI
            TopI = Sheets("Data").Cells(i + DOF, 2)
            BaseI = Sheets("Data").Cells(i + DOF, 3)
            Samples = CInt((BaseI - TopI) / Inc)
            Sheets("Samples").Cells(i, 12) = Samples
            Application.StatusBar = i
          Next i
          
          For i = 1 To TS
           Sheets("Samples").Cells(i, 8) = Top + (i - 1) * Inc
          Next i
          
          For i = 1 To TI
            SII = Sheets("Samples").Cells(i, 12)
            If i = TI Then SII = SII + 1
            For j = 1 To SII
              Counter = Counter + 1
              Sheets("Samples").Cells(Counter, 9) = Sheets("Data").Cells(i + DOF, 13)
              Bounter = Bounter + 1
              Sheets("Samples").Cells(Bounter, 10) = Sheets("Data").Cells(i + DOF, 16)
             Next j
          Next i
          
        End If                                    'If not Cancelled
    '---------------->>> End of calculation loop. Everything after this line is after the calculation is done. <<<-----------------------
        
        Range("A1").Select
        ActiveWindow.ScrollRow = Range("A1").Row
        
        Application.ScreenUpdating = True
        Application.DisplayStatusBar = OldStatusbar
    End Sub
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    06-22-2016
    Location
    Utrecht
    MS-Off Ver
    MS Office 2013
    Posts
    2

    Re: Starting a new calculation loop when a new entry in column A is reached

    Anyone experience with this?

+ 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. Lock column stopping further entry when pre defined total reached
    By Aestivator1 in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 10-20-2015, 06:10 PM
  2. Replies: 2
    Last Post: 11-28-2013, 03:13 PM
  3. Perform calculation only when a certain date is reached
    By Juleskor in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-07-2013, 10:32 PM
  4. loop for shifting one column after each calculation
    By burnmeister in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-02-2013, 03:53 PM
  5. [SOLVED] Find entry in column that match another which is already based on a calculation
    By StrydomM in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-11-2012, 07:17 AM
  6. Replies: 5
    Last Post: 09-27-2012, 07:30 PM
  7. Replies: 5
    Last Post: 01-04-2006, 03:46 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