Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copy columns if cell row has a value

* Need to read each row in a spreasheet (number of rows in the
spreadsheet will always be changing)

* if there is a value in Cells(i, 4) and
the text in Cells(i, 3) = 'Active'

I want to copy columns 1,4,5,7,10 to a new workbook. [one or more row
makes up one record - the value in column 4 signifies a new record]

* This new spreadsheet will be turned into a CSV to feed another
program.


How would you approach this?
Any help is appreciated!!
thanks
-christia

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Copy columns if cell row has a value

Dim rng as Range, rw as long, dest as Range
Dim cell as Range
with Activesheet
set rng = Intersect(.columns(1),.usedrange).Cells
End with
set dest = workbooks("Otherbook.xls").Worksheets(1).Range("A1 ")
rw = 0
for each cell in rng
if cell.offset(0,3) < "" and cell.offset(0,2)="Active" then
rw = rw + 1
cell.Range("A1,A4,A5,A7,A10").copy Destination:=dest(rw)
End if
Next

--
Regards,
Tom Ogilvy

"christian " wrote in message
...
* Need to read each row in a spreasheet (number of rows in the
spreadsheet will always be changing)

* if there is a value in Cells(i, 4) and
the text in Cells(i, 3) = 'Active'

I want to copy columns 1,4,5,7,10 to a new workbook. [one or more rows
makes up one record - the value in column 4 signifies a new record]

* This new spreadsheet will be turned into a CSV to feed another
program.


How would you approach this?
Any help is appreciated!!
thanks
-christian


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copy columns if cell row has a value

Thanks - got me 90% there. For some reason I'm only getting the first
column though...4,5,7,10 don't get copied over.

Tried to figure it out on my own but pulling what little hair I have
left out. I'm not sure I understand the use of ("A1,A4,A5...") - does
"A" constitute the ROW and 1,4,5 the Column?

Thanks again - HUGE help!!!
-c


---
Message posted from http://www.ExcelForum.com/

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Copy columns if cell row has a value

Sorry, got my rows and columns reversed. This works
Sub BBBB()
Dim rng As Range, rw As Long, dest As Range
Dim cell As Range
With ActiveSheet
Set rng = Intersect(.Columns(1), .UsedRange).Cells
End With
Set dest = Workbooks("Otherbook.xls").Worksheets(1).Range("A1 ")
rw = 0
For Each cell In rng
If cell.Offset(0, 3) < "" And cell.Offset(0, 2) = "Active" Then
rw = rw + 1
cell.Range("A1,D1,E1,G1,J1").Copy Destination:=dest(rw)
End If
Next
End Sub


so cell.Range("A1,D1,E1,G1,J1").

is relative to the cell where it is anchored. co Cell.Range("D1") would be
column D (column 4) since cell is in column A.

--
Regards,
Tom Ogilvy


"christian " wrote in message
...
Thanks - got me 90% there. For some reason I'm only getting the first
column though...4,5,7,10 don't get copied over.

Tried to figure it out on my own but pulling what little hair I have
left out. I'm not sure I understand the use of ("A1,A4,A5...") - does
"A" constitute the ROW and 1,4,5 the Column?

Thanks again - HUGE help!!!
-c


---
Message posted from http://www.ExcelForum.com/



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
copy a columns kevcar40 Excel Discussion (Misc queries) 2 September 18th 08 10:42 AM
How do I copy columns between worksheets if the columns don't matc Miriam Excel Worksheet Functions 10 June 12th 06 04:29 PM
Copy columns values into separate columns Mike_can Excel Discussion (Misc queries) 7 May 27th 06 12:32 AM
how do I copy text to columns from one cell to another? Stressed! Excel Discussion (Misc queries) 8 May 11th 06 08:01 PM
Copy Cell Across Columns ExcelMonkey[_90_] Excel Programming 2 February 27th 04 09:38 PM


All times are GMT +1. The time now is 11:16 PM.

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

About Us

"It's about Microsoft Excel"