Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 913
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VB Script to copy incremental data from one sheet of workbook to o Samarth Excel Discussion (Misc queries) 1 May 25th 10 11:58 AM
Conditionally copy from multiple sheets to one sheet Pam[_3_] Excel Programming 2 April 29th 09 10:30 PM
export sheet data for batch script john coon Excel Programming 0 March 4th 07 03:24 PM
Conditionally Fill a sheet row if cell value in another sheet 0 nstx Excel Worksheet Functions 2 November 6th 05 03:04 PM
Excel macro script to copy only formulas and not values from one sheet to another Kate[_4_] Excel Programming 5 August 13th 04 12:45 AM


All times are GMT +1. The time now is 11:33 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"