Consulting

Results 1 to 9 of 9

Thread: Nested Loops?

  1. #1

    Unhappy Nested Loops?

    I am trying to work out a macro that will do the following
    Column A will be pasted into Cell $F$2, one value at a time.
    Column B will be pasted into Cell $F$3, one value at a time.
    Cells F2 and F3 are then input into some formulas to create a value in $R$4. This part is done with formulas not part of the macro.
    Then this value $r$4 needs to be pasted into Column C. I hope I have explained this well enough for you to understand. So I think I need Loops within loops so it will take one calculation at a time and place into column C before it goes to the next set of numbers in Column A and B.
    Do you have a ny suggestions?
    All the data is on one work sheet.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Give a couple of examples so we can visualise it.
    ____________________________________________
    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

  3. #3
    I would like to send you an attachment but can't see the manage attachement button.
    When I paste in the worksheet it comes out in text.
    A B C D E F R
    2 98
    3

    2 3 98
    1 2
    3 1

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    That isn't excatly helpful, it just a string of characters.

    Spreadsheet layout, and expected results ould be more helpful.
    ____________________________________________
    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

  5. #5
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    I don't see why you would need nested loops for what you seem to want.

    But then again what you seem to want isn't too clear.

    If you want to attach a workbook use the Go Advanced button.

  6. #6
    Thanks for helping me find that Manage Atatchement button. I am new to this site and haven't ever attached anything before.
    Ok, On this SS
    Column L needs to be pasted into B2, one value at a time
    Column M needs to be pasted into B3, one at a time
    This causes a caluclation to be entered into H18 (Total)
    This calulation is not part of the macro,
    Then the resluting number from H18 needs to be pasted into the N column, in the corresponding cell. So L3, and M3 would be the values that produced N3
    Thanks for looking at this. I thought the nested loops would help the progression of filling in column N, one value at a time?

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    There are #REF!s everywhere, so H18 isn't calculating anything.
    ____________________________________________
    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

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    But all you need when you tidy up the errors is

    [vba]

    Public Sub ProcessData()
    Const TEST_COLUMN As String = "L" '<=== change to suit
    Dim i As Long
    Dim iLastRow As Long

    With ActiveSheet

    iLastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
    For i = 3 To iLastRow
    .Range("B2").Value = .Cells(i, TEST_COLUMN).Value
    .Range("B3").Value = .Cells(i, TEST_COLUMN).Offset(0, 1).Value
    .Cells(i, TEST_COLUMN).Offset(0, 2).Value = .rangee("H18").Value
    Next i

    End With

    End Sub
    [/vba]
    ____________________________________________
    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

  9. #9

    Solved-You are awesome

    Thanks for the code. I am rotton with counters.

Posting Permissions

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