+ Reply to Thread
Results 1 to 4 of 4

looping

  1. #1
    Registered User
    Join Date
    01-26-2005
    Posts
    3

    looping

    I can't find the information I am looking for on loops.

    I have the following code and still need to add a couple of more loops.
    I have a cell (S1) with the number of loops needed figured out by a calculation.

    Sub Surface()

    Range("A27").Select

    varInput = InputBox("Enter the date analyzed.")
    Sheets("Information").Range("C65").Value = varInput

    varInput = InputBox("At what depth did this section of the well end at?")
    Sheets("Information").Range("E65").Value = varInput

    varInput = InputBox("Enter the mud type (either Gel Chem or Floc Water).")
    Sheets("Information").Range("F65").Value = varInput

    varInput = InputBox("Enter the volume of mud landsprayed.")
    Sheets("Information").Range("H65").Value = varInput

    varInput = InputBox("Enter the specific gravity (1.0-1.5).")
    Sheets("Information").Range("I65").Value = varInput

    varInput = InputBox("Enter pH.")
    Sheets("Information").Range("J65").Value = varInput

    varInput = InputBox("Enter EC.")
    Sheets("Information").Range("K65").Value = varInput

    varInput = InputBox("Enter Na.")
    Sheets("Information").Range("L65").Value = varInput

    varInput = InputBox("Enter Ca.")
    Sheets("Information").Range("M65").Value = varInput

    varInput = InputBox("Enter TH.")
    Sheets("Information").Range("N65").Value = varInput

    varInput = InputBox("Enter Cl.")
    Sheets("Information").Range("O65").Value = varInput

    varInput = InputBox("Enter NO3.")
    Sheets("Information").Range("P65").Value = varInput


    Range("A27").Select

    End Sub
    Sub Fasthole()

    Range("A27").Select

    varInput = InputBox("Enter the date analyzed.")
    Sheets("Information").Range("C66").Value = varInput

    varInput = InputBox("At what depth did this section of the well end at?")
    Sheets("Information").Range("E66").Value = varInput

    varInput = InputBox("Enter the mud type (either Gel Chem or Floc Water).")
    Sheets("Information").Range("F66").Value = varInput

    varInput = InputBox("Enter the volume of mud landsprayed.")
    Sheets("Information").Range("H66").Value = varInput

    varInput = InputBox("Enter the specific gravity (1.0-1.5).")
    Sheets("Information").Range("I66").Value = varInput

    varInput = InputBox("Enter pH.")
    Sheets("Information").Range("J66").Value = varInput

    varInput = InputBox("Enter EC.")
    Sheets("Information").Range("K66").Value = varInput

    varInput = InputBox("Enter Na.")
    Sheets("Information").Range("L66").Value = varInput

    varInput = InputBox("Enter Ca.")
    Sheets("Information").Range("M66").Value = varInput

    varInput = InputBox("Enter TH.")
    Sheets("Information").Range("N66").Value = varInput

    varInput = InputBox("Enter Cl.")
    Sheets("Information").Range("O66").Value = varInput

    varInput = InputBox("Enter NO3.")
    Sheets("Information").Range("P66").Value = varInput


    Range("A27").Select

    End Sub
    Sub Intermediate()

    Range("A27").Select

    varInput = InputBox("Enter the date analyzed.")
    Sheets("Information").Range("C67").Value = varInput

    varInput = InputBox("At what depth did this section of the well end at?")
    Sheets("Information").Range("E67").Value = varInput

    varInput = InputBox("Enter the mud type (either Gel Chem or Floc Water).")
    Sheets("Information").Range("F67").Value = varInput

    varInput = InputBox("Enter the volume of mud landsprayed.")
    Sheets("Information").Range("H67").Value = varInput

    varInput = InputBox("Enter the specific gravity (1.0-1.5).")
    Sheets("Information").Range("I67").Value = varInput

    varInput = InputBox("Enter pH.")
    Sheets("Information").Range("J67").Value = varInput

    varInput = InputBox("Enter EC.")
    Sheets("Information").Range("K67").Value = varInput

    varInput = InputBox("Enter Na.")
    Sheets("Information").Range("L67").Value = varInput

    varInput = InputBox("Enter Ca.")
    Sheets("Information").Range("M67").Value = varInput

    varInput = InputBox("Enter TH.")
    Sheets("Information").Range("N67").Value = varInput

    varInput = InputBox("Enter Cl.")
    Sheets("Information").Range("O67").Value = varInput

    varInput = InputBox("Enter NO3.")
    Sheets("Information").Range("P67").Value = varInput


    Range("A27").Select

    End Sub

    I think you get the point. Any input appreciated.
    Thanks
    Wendy

  2. #2
    Forum Contributor
    Join Date
    11-09-2004
    Posts
    451
    Do it for other procedure similary

    Sub Surface()
    Dim ar, ar1 As Variant
    ar = Array("Enter the date analyzed.", "At what depth did this section of the well end at?", "Enter the mud type (either Gel Chem or Floc Water).", "Enter the volume of mud landsprayed.", "Enter the specific gravity (1.0-1.5).", "Enter pH.", "Enter EC.", "Enter Na.", "Enter Ca.", "Enter TH.", "Enter Cl.", "Enter NO3.")
    ar1 = Array("c65", "e65", "f65", "h65", "i65", "j65", "k65", "l65", "m65", "n65", "o65", "p65")
    Range("A27").Select
    For i = 0 To UBound(ar)
    varInput = InputBox(ar(i))
    Sheets("Sheet2").Range(ar1(i)).Value = varInput
    Next
    End Sub

  3. #3
    Registered User
    Join Date
    01-26-2005
    Posts
    3

    Question one more question on loop

    That worked great when you know how many times you need the information. Thanks

    But still wondering if its possible to have a loop as I have a similar situation with soils but don't know how many there are. The number of soils is calculated in a cell that can be referenced in the loop.

    Wendy

  4. #4
    Forum Contributor
    Join Date
    11-09-2004
    Posts
    451
    The number of soils is calculated in a cell that can be referenced in the loop, surely that can be done.

    for eg if number of soils is calculated in cell a1

    for i=0 to range("a1").value
    'your code

    next

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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