Home |
Search |
Today's Posts |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
KeriM wrote:
I have a two part question. I've searched around, but haven't had any luck finding an answer. I need to copy certain columns by header since the columns are not always in the same place. For example, I have a sheet with columns labeled "1-5" and I need to copy columns 1-3, and 5. The second part is that I don't want to copy the whole column, just up to the last cell of data. I've had luck with xldown/xlup, however, this data is non-contiguous, so there are blank cells mixed-in which will render these commands useless. Any help is greatly appreciated. Thanks! Unfortunately, I can't provide any sample spreadsheet data as this is sensitive information. I hope I explained myself well enough. Thank you! Something like this, perhaps? Sub selectiveCopy() Dim bottom As Range, headerRow As Range, cell As Range Set headerRow = Range("A:A") For Each cell In headerRow Select Case cell.Value Case "value1 to copy", "value2 to copy", "value3 to copy" Set bottom = Cells(Cells.SpecialCells(xlCellTypeLastCell).Row, _ cell.Column) If bottom.Value < "" Then Range(cell.Address & ":" & bottom.Address).Copy Else Range(cell.Address & ":" & Cells(bottom.End(xlUp).Row, _ cell.Column).Address).Copy End If 'code here to paste wherever you want it End Select Next End Sub -- What a totally inappropriate, tasteless and vile comment! I love it! |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
select and move columns by their name in header row | Excel Programming | |||
How to print one header over several columns of data | Excel Discussion (Misc queries) | |||
Copy and Paste LAST ROW of data: non-contiguous Row, contiguous Column | Excel Programming | |||
Select any row, copy data from specific columns | Excel Programming | |||
Copying non-contiguous columns to contiguous columns | Excel Programming |