Consulting

Results 1 to 2 of 2

Thread: cleaning up sheet/cell references

  1. #1

    Red face cleaning up sheet/cell references

    This is the first piece of code I've written by myself (and i'm quite proud of it ). I realise though that there are pieces that could have been written better, can anyone point anything?

    I figure there is a better way to reference the cells (e.g. critloc) instead of how I did it can someone show me how?

    [VBA]Sub ALM2()
    '
    ' AutoALM Macro
    ' Macro recorded 11/26/2008 by
    '
    '
    Dim Criteria As String

    With Worksheets("Aleem")

    Dim nextrow As Long
    Dim critloc As Long
    Dim result As Long
    Dim sampdat As Long
    Dim rowcount As Long
    Dim lowout As Long
    Dim highout As Long

    With Application

    .ScreenUpdating = False
    .Calculation = xlCalculationManual
    End With


    Range("J1").Select
    Range(Selection, Selection.End(xlDown)).Select

    rowcount = Selection.Count - 1

    'this is where the stream names are
    critloc = 266

    'put the result heading here
    result = 15

    'put the sample data under the corresponding result heading
    sampdat = 271

    'lower outliers
    lowout = 268

    'higher outliers
    highout = 269

    Do While rowcount > 0



    Criteria = Cells.Item(critloc)

    Cells.Item(result) = Criteria

    Selection.AutoFilter Field:=3, Criteria1:=Criteria

    Selection.AutoFilter Field:=8, Criteria1:=">0.691", Operator:=xlAnd, _
    Criteria2:="<1.5403758"

    Range("H2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Cells.Item(sampdat).Select
    ActiveSheet.Paste


    critloc = critloc + 256
    highout = highout + 256
    lowout = lowout + 256
    result = result + 1
    sampdat = sampdat + 1
    rowcount = rowcount - 1

    Loop




    End With

    With Application

    .Calculation = xlCalculationAutomatic
    .ScreenUpdating = True
    End With
    Selection.AutoFilter Field:=3
    Selection.AutoFilter Field:=8

    End Sub[/VBA]

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    What is it doing?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •