Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Script to conditionally copy data to another sheet?
I have a workbook that I've been extensively automating but unfortunately I'm
still pretty new to VBA. I have a long range of data that I'd like to copy to a new sheet *only when* a particular column contains data. For example, my data range starts in cell B35 of Sheet1 and goes to L301. I'd like to copy only those rows of data when a value has been placed in column E (column E cells are blank by default) to Sheet2. I'd also like the information to port over as values only. Can anyone help me out? Thanks in advance for any and all help!! |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Script to conditionally copy data to another sheet?
On Fri, 31 Jul 2009 01:24:02 -0700, tpmax
wrote: I have a workbook that I've been extensively automating but unfortunately I'm still pretty new to VBA. I have a long range of data that I'd like to copy to a new sheet *only when* a particular column contains data. For example, my data range starts in cell B35 of Sheet1 and goes to L301. I'd like to copy only those rows of data when a value has been placed in column E (column E cells are blank by default) to Sheet2. I'd also like the information to port over as values only. Can anyone help me out? Thanks in advance for any and all help!! Try this macro: Sub copy_conditionally() Set my_destination = Worksheets("Sheet6").Range("B35") ' this is the upper left corner of the destination row_offset = 0 For Each c In Range("E35:E301") If c < "" Then c.Resize(1, 11).Offset(0, -3).Copy my_destination.Offset(row_offset, 0).PasteSpecial (xlPasteValues) row_offset = row_offset + 1 End If Next c Application.CutCopyMode = False End Sub You may want to clear the target sheet in the beginning of the macro. If you want blank rows (gaps) in the destination where the E column is blank you can move the increase of row_offset outside the If - Then. Hope this helps / Lars-Åke |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
VB Script to copy incremental data from one sheet of workbook to o | Excel Discussion (Misc queries) | |||
Conditionally copy from multiple sheets to one sheet | Excel Programming | |||
export sheet data for batch script | Excel Programming | |||
Conditionally Fill a sheet row if cell value in another sheet 0 | Excel Worksheet Functions | |||
Excel macro script to copy only formulas and not values from one sheet to another | Excel Programming |