I have a worksheet where each row (except the header) represents a single entry, each column a field (pretty standard stuff). The fields go up to column BB.
I want to copy certain entries (those matching a particular value for a particular identifying field) onto another sheet. However, I don’t want all the fields that are on the original sheet, only about 10, which aren’t contiguous on the original sheet.
Therefore, for each (valid) row, I would want to do something like this:
for each origRow in origSheet.Rows
if strcomp(origRow.cells(idCellNumber).value, myId, vbTextCompare) = 0 then
copySheet.Row(copySheetRowNumber).value = origRow.Range(Cells(1), Cells(8), Cells(15), Cells(4))
copySheetRowNumber++
end if
next
Obviously this code is invalid. Furthermore, I can’t simply copy the entries as a whole and then delete the irrelevant columns, since the sheet contains existing data which would be deleted. Can anyone suggest the fastest way to accomplish this?
1 Answer