+ Reply to Thread
Results 1 to 7 of 7

Simple loop problem

  1. #1
    Christy
    Guest

    Simple loop problem

    I have a simple loop that is not working and I just see why. I am trying to
    loop through column F and if there is an X in the cell, copy the value from
    column A in the same row to another worksheet. I loop is only picking up the
    last x in column F?
    Any help would be greatly appreciated.

    Sub DailyList()
    Dim WorkRange As Range
    Dim i As Integer
    Set WorkRange = Sheet3.Range("a300").End(xlUp).Offset(1, 0)
    i = 2
    For i = 2 To 300 Step 1
    If Sheet1.Cells(i, 6) = "x" Then
    WorkRange.Value = Sheet1.Cells(i, 1).Value
    End If
    Next
    End Sub

  2. #2
    Christy
    Guest

    RE: Simple loop problem

    Thank goodness it's Friday! I see I forgot to put a .value in my code


    "Christy" wrote:

    > I have a simple loop that is not working and I just see why. I am trying to
    > loop through column F and if there is an X in the cell, copy the value from
    > column A in the same row to another worksheet. I loop is only picking up the
    > last x in column F?
    > Any help would be greatly appreciated.
    >
    > Sub DailyList()
    > Dim WorkRange As Range
    > Dim i As Integer
    > Set WorkRange = Sheet3.Range("a300").End(xlUp).Offset(1, 0)
    > i = 2
    > For i = 2 To 300 Step 1
    > If Sheet1.Cells(i, 6) = "x" Then
    > WorkRange.Value = Sheet1.Cells(i, 1).Value
    > End If
    > Next
    > End Sub


  3. #3
    Don Guillett
    Guest

    Re: Simple loop problem

    what you are doing here is copying ALL to the same cell instead of the next
    available cell.

    WorkRange.Value = Sheet1.Cells(i, 1).Value


    --
    Don Guillett
    SalesAid Software
    [email protected]
    "Christy" <[email protected]> wrote in message
    news:[email protected]...
    >I have a simple loop that is not working and I just see why. I am trying to
    > loop through column F and if there is an X in the cell, copy the value
    > from
    > column A in the same row to another worksheet. I loop is only picking up
    > the
    > last x in column F?
    > Any help would be greatly appreciated.
    >
    > Sub DailyList()
    > Dim WorkRange As Range
    > Dim i As Integer
    > Set WorkRange = Sheet3.Range("a300").End(xlUp).Offset(1, 0)
    > i = 2
    > For i = 2 To 300 Step 1
    > If Sheet1.Cells(i, 6) = "x" Then
    > WorkRange.Value = Sheet1.Cells(i, 1).Value
    > End If
    > Next
    > End Sub




  4. #4
    Toppers
    Guest

    RE: Simple loop problem

    Hi,
    You need to increment WorkRange to point to next row

    Sub DailyList()
    Dim WorkRange As Range
    Dim i As Integer
    Set WorkRange = Sheet3.Range("a300").End(xlUp).Offset(1, 0)
    i = 2
    For i = 2 To 300 Step 1
    If Sheet1.Cells(i, 6) = "x" Then
    WorkRange.Value = Sheet1.Cells(i, 1).Value
    Set WorkRange = WorkRange.Offset(1, 0)
    End If
    Next
    End Sub

    "Christy" wrote:

    > Thank goodness it's Friday! I see I forgot to put a .value in my code
    >
    >
    > "Christy" wrote:
    >
    > > I have a simple loop that is not working and I just see why. I am trying to
    > > loop through column F and if there is an X in the cell, copy the value from
    > > column A in the same row to another worksheet. I loop is only picking up the
    > > last x in column F?
    > > Any help would be greatly appreciated.
    > >
    > > Sub DailyList()
    > > Dim WorkRange As Range
    > > Dim i As Integer
    > > Set WorkRange = Sheet3.Range("a300").End(xlUp).Offset(1, 0)
    > > i = 2
    > > For i = 2 To 300 Step 1
    > > If Sheet1.Cells(i, 6) = "x" Then
    > > WorkRange.Value = Sheet1.Cells(i, 1).Value
    > > End If
    > > Next
    > > End Sub


  5. #5
    galimi
    Guest

    RE: Simple loop problem

    Christy,

    Try the following

    Sub Daily()

    Set oFind = shtFind.Range("f1")
    Set oCopy = shtCopy.Range("a1")

    Do Until oFind.Offset(i).Row > shtFind.UsedRange.Rows.Count
    If oFind.Offset(i) = "x" Then
    oCopy.Offset(i) = oFind.Offset(i, -5)
    End If
    i = i + 1
    Loop

    End Sub

    You did not set an adjustable offset for your workrange object. My code
    will also take into account any sized spreadsheet.
    --
    http://HelpExcel.com
    1-888-INGENIO
    1-888-464-3646
    x0197758


    "Christy" wrote:

    > I have a simple loop that is not working and I just see why. I am trying to
    > loop through column F and if there is an X in the cell, copy the value from
    > column A in the same row to another worksheet. I loop is only picking up the
    > last x in column F?
    > Any help would be greatly appreciated.
    >
    > Sub DailyList()
    > Dim WorkRange As Range
    > Dim i As Integer
    > Set WorkRange = Sheet3.Range("a300").End(xlUp).Offset(1, 0)
    > i = 2
    > For i = 2 To 300 Step 1
    > If Sheet1.Cells(i, 6) = "x" Then
    > WorkRange.Value = Sheet1.Cells(i, 1).Value
    > End If
    > Next
    > End Sub


  6. #6
    Bob Phillips
    Guest

    Re: Simple loop problem

    That shouldn't be the reason, Value is the default property.

    --
    HTH

    Bob Phillips

    (remove nothere from email address if mailing direct)

    "Christy" <[email protected]> wrote in message
    news:[email protected]...
    > Thank goodness it's Friday! I see I forgot to put a .value in my code
    >
    >
    > "Christy" wrote:
    >
    > > I have a simple loop that is not working and I just see why. I am trying

    to
    > > loop through column F and if there is an X in the cell, copy the value

    from
    > > column A in the same row to another worksheet. I loop is only picking up

    the
    > > last x in column F?
    > > Any help would be greatly appreciated.
    > >
    > > Sub DailyList()
    > > Dim WorkRange As Range
    > > Dim i As Integer
    > > Set WorkRange = Sheet3.Range("a300").End(xlUp).Offset(1, 0)
    > > i = 2
    > > For i = 2 To 300 Step 1
    > > If Sheet1.Cells(i, 6) = "x" Then
    > > WorkRange.Value = Sheet1.Cells(i, 1).Value
    > > End If
    > > Next
    > > End Sub




  7. #7
    Christy
    Guest

    Re: Simple loop problem

    Thank you all very much!

    "Don Guillett" wrote:

    > what you are doing here is copying ALL to the same cell instead of the next
    > available cell.
    >
    > WorkRange.Value = Sheet1.Cells(i, 1).Value
    >
    >
    > --
    > Don Guillett
    > SalesAid Software
    > [email protected]
    > "Christy" <[email protected]> wrote in message
    > news:[email protected]...
    > >I have a simple loop that is not working and I just see why. I am trying to
    > > loop through column F and if there is an X in the cell, copy the value
    > > from
    > > column A in the same row to another worksheet. I loop is only picking up
    > > the
    > > last x in column F?
    > > Any help would be greatly appreciated.
    > >
    > > Sub DailyList()
    > > Dim WorkRange As Range
    > > Dim i As Integer
    > > Set WorkRange = Sheet3.Range("a300").End(xlUp).Offset(1, 0)
    > > i = 2
    > > For i = 2 To 300 Step 1
    > > If Sheet1.Cells(i, 6) = "x" Then
    > > WorkRange.Value = Sheet1.Cells(i, 1).Value
    > > End If
    > > Next
    > > End Sub

    >
    >
    >


+ 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