+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    03-10-2010
    Location
    San Antonio, TX
    MS-Off Ver
    Excel 2003
    Posts
    1

    Macro to copy certain cells in row

    I have a workbook with several worksheets. One is called BaseBid. I need a macro which will look at the values in columns J and K. If there is an "x" in column J, I want to copy the values from columns C and D of that row into the last row of a sheet called SL. If there is an "x" in column K, then I want to copy the values from columns C and G of that row into the last row of the SL worksheet. The data on the BaseBid sheet starts in row 6.

    I have two macros which almost do what I want. The first copies the values from the right cells on BaseBid to SL. But it does not go through the whole BaseBid sheet, which I need it to do. The second one uses a loop, and it does go through the whole spreadsheet, but it is copying the entire line instead of just the cells I need. Can someone please help? I am pasting the code for both macros below.

    Sub InsertSL()
    Dim LastRow As Long
    Dim rng As Range
    LastRow = Last(1, rng)
    rng.Parent.Cells(LastRow + 1, 2).Value = "=BaseBid!RC[1]"
    rng.Parent.Cells(LastRow + 1, 4).Value = "=SUM(BaseBid!RC[2],BaseBid!RC[5])"

    End Sub

    Sub test2()

    Set a = Sheets("BaseBid")
    Set b = Sheets("SL")
    Dim x
    Dim z

    x = 1
    z = 6

    Do Until IsEmpty(a.Range("I" & z))

    If a.Range("J" & z) = "x" Then
    x = x + 1
    b.Rows(x).Value = a.Rows(z).Value

    Else

    If a.Range("K" & z) = "x" Then
    x = x + 1
    b.Rows(x).Value = a.Rows(z).Value

    End If
    End If
    z = z + 1
    Loop
    End Sub

  2. #2
    Forum Moderator shg's Avatar
    Join Date
    06-21-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007
    Posts
    25,134

    Re: Macro to copy certain cells in row

    Welcome to the forum, Liz.

    Please take a few minutes to read the forum rules, and then edit your post to add code tags.

    Thanks.
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

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