Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > microsoft.public.excel.programming > #109870

Re: Help condensing 2 step process

From GS <gs@v.invalid>
Newsgroups microsoft.public.excel.programming
Subject Re: Help condensing 2 step process
Date 2017-02-21 18:05 -0500
Organization A noiseless patient Spider
Message-ID <o8ih06$dlb$1@dont-email.me> (permalink)
References <d5b37f11-2395-4170-933f-e9568bf6d312@googlegroups.com> <o8guc7$lgj$1@dont-email.me>

Show all headers | View raw


FWIW:
Each time VB encounters an 'IF' statement it fires a new evaluation 
process. In this scenario, things would process more efficiently (and 
faster) if coded to eliminate unecessary 'IF' statements...

Sub Check_Weight2()
' This directly reads/writes the worksheet (faster)
  Dim rng, c
  Const lWt& = 1136

  For Each c In Sheets("TMS DATA").Range("O6:O350")
    Set rng = c.Offset(, 37)
    With Cells(c.Row, 1)
      On Error Resume Next '//ignore divide by zero
      rng.Value = (c.Value / c.Offset(, -1).Value)
      If rng.Value > lWt Then .Resize(1, 31).Interior.ColorIndex = 0
    End With
  Next 'rng
  Set rng = Nothing
End Sub

Sub CheckWeight3()
' This handles the process in memory (much faster);
' It assumes all columns being processed are inside UsedRange.
  Dim vRng, n&, lCol&, lCol2&
  Const lWt& = 1136: Const lStart& = 6: Const lStop& = 350

  With Sheets("TMS DATA")
    vRng = .UsedRange: lCol = .Columns("O").Column
    lCol2 = lCol + 37 '(15+37=52) ~ Columns("AZ")

    For n = lStart To lStop
      On Error Resume Next '//ignore divide by zero
      vRng(n, lCol2) = vRng(n, lCol) / vRng(n, lCol - 1)
    Next 'n
    On Error GoTo 0

    'Shade cells that fit criteria
    .UsedRange = vRng
    For n = lStart To lStop
      If vRng(n, lCol2) > lWt Then _
        .Cells(n, 1).Resize(1, 31).Interior.ColorIndex = 0
    Next 'n
  End With 'Sheets("TMS DATA")
End Sub

-- 
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
  comp.lang.basic.visual.misc
  microsoft.public.vb.general.discussion

Back to microsoft.public.excel.programming | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Help condensing 2 step process Living the Dream <noodnutt@gmail.com> - 2017-02-21 00:06 -0800
  Re: Help condensing 2 step process Claus Busch <claus_busch@t-online.de> - 2017-02-21 09:41 +0100
    Re: Help condensing 2 step process GS <gs@v.invalid> - 2017-02-21 18:05 -0500
      Re: Help condensing 2 step process Living the Dream <noodnutt@gmail.com> - 2017-03-28 05:03 -0700
      Re: Help condensing 2 step process Living the Dream <noodnutt@gmail.com> - 2017-03-29 02:31 -0700
        Re: Help condensing 2 step process GS <gs@v.invalid> - 2017-03-29 11:57 -0400
    Re: Help condensing 2 step process Living the Dream <noodnutt@gmail.com> - 2017-03-28 05:02 -0700

csiph-web