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
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
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks