I have a workbook with two worksheets in it. In one worksheet called Materials List I have multiple rows that when selected, automate into the other worksheet named BOM. In the Materials List tab, I need columns H and I to combine (not sum, just combine descriptions) into column C in the BOM tab. You can see in the code where I just typed in H+I in one spot... and C in the respective spot. I don't want to erase any of my other code though! HELP PLEASE! and thanks in advance!
Code:
Sub CopyData()
Dim Cell As Range
Dim DstWks As Worksheet
Dim R As Long
Dim Rng As Range
Dim RngEnd As Range
Dim SrcCols() As Variant
Dim SrcWks As Worksheet
'Name of the destination worksheet
Set DstWks = ThisWorkbook.Worksheets("BOM")
'Name of the source data worksheet
Set SrcWks = ThisWorkbook.Worksheets("Material List")
'Set search range to start at E1 - Change this if you need to.
Set Rng = SrcWks.Range("A6")
Set RngEnd = SrcWks.Cells(Rows.Count, Rng.Column).End(xlUp)
Set Rng = IIf(RngEnd.Row > Rng.Row, SrcWks.Range(Rng, RngEnd), Rng)
'Next available row on the destination worksheet.
Set RngEnd = DstWks.Cells.Find("*", , xlValues, xlWhole, xlByRows, xlPrevious, False)
If RngEnd Is Nothing Then
A = 2
Else
A = RngEnd.Row + 1
End If
'Data columns on source worksheet to copy.
SrcCols = Array("G", "H+I", "I", "J", "K", "L", "O", "M", "N")
For Each Cell In Rng
If Cell = "y" Then
R = Cell.Row
DstWks.Cells(A, "A") = SrcWks.Cells(R, SrcCols(0))
DstWks.Cells(A, "C") = SrcWks.Cells(R, SrcCols(1))
DstWks.Cells(A, "B") = SrcWks.Cells(R, SrcCols(2))
DstWks.Cells(A, "D") = SrcWks.Cells(R, SrcCols(3))
DstWks.Cells(A, "E") = SrcWks.Cells(R, SrcCols(4))
DstWks.Cells(A, "F") = SrcWks.Cells(R, SrcCols(5))
DstWks.Cells(A, "I") = SrcWks.Cells(R, SrcCols(6))
DstWks.Cells(A, "N") = SrcWks.Cells(R, SrcCols(7))
DstWks.Cells(A, "T") = SrcWks.Cells(R, SrcCols(8))
A = A + 1
End If
Next Cell
End Sub