+ Reply to Thread
Results 1 to 2 of 2

Thread: Looping through different columns in a range to populate the data in another workshee

  1. #1
    Registered User
    Join Date
    12-15-2011
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    1

    Looping through different columns in a range to populate the data in another workshee

    Dear all,

    I want to populate some columns base don some condition in 2 different columns in another worksheet. this is what I am doing:

    Set spRange = Worksheet1.Range("D3", "H" & GetLastRowWithData)
    //where D and H column contains values such as "forward" and "roll" respecitvely along with lots of other values

    For Each cell In spRange
    If cell.Value = "Forward" Then
    copyRowTo sharePoint.Range("C" & cell.Row), Worksheet2, 1 //copying row to next sheet successfully
    End If
    Next cell //this function is successfully copying rows which are having value as forward in column D.

    .

    but What I want is to copy rows ONLY if the value in column D and H is "Forward" and "roll" respectively or may be something like:

    For Each cell In spRange
    If cell.Value = "Forward" And cell.value ="Roll" Then
    copyRowTo sharePoint.Range("C" & cell.Row), ChartSpotDollar, 1 //copying row to next sheet successfully
    End If
    Next cell


    How can I do this?

    Any help would be much appreiacted..!!

  2. #2
    Forum Contributor
    Join Date
    11-04-2011
    Location
    pak
    MS-Off Ver
    Excel 2007
    Posts
    122

    Re: Looping through different columns in a range to populate the data in another work

    Hi, welcome to the forum.Please take a moment to read the forum rules. suppose very first row has column headings and try this code:
    Sub shau()
    Dim rngLast As Range, i As Long, j As Long,k as long
    Set rngLast = Sheets("sheet1").Range("D1").SpecialCells(xlCellTypeLastCell)
    j = rngLast.Row
    For i = 1 To j
    With Sheets("sheet1")
        If Cells(i, 4).Value = "forward" And Cells(i, 8).Value = "roll" Then
            .Rows(i).Copy
        Else
    GoTo error
        End If
    End With
    With Sheets("sheet2")
        k = .UsedRange.Rows.Count
        .Rows(k + 1).PasteSpecial
    End With
    error:
    Next
    End Sub
    Last edited by shaukat; 12-15-2011 at 04:52 PM. Reason: explaination

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0