PC Review


Reply
Thread Tools Rate Thread

copy rows in range if data in first cell

 
 
Wes_A
Guest
Posts: n/a
 
      19th Apr 2010
I need to select from a range of rows - only those having data (formula
result) in the first cell. There will be some rows without data in the first
cell but they would contain a formula - these shoudl not be selected for copy.
I want to select and copy all the rows having data in the first cell in
order to paste these rows as values into a separate sheet in another workbook.
Any suggestion?
 
Reply With Quote
 
 
 
 
Chip Pearson
Guest
Posts: n/a
 
      19th Apr 2010
Try some code like the following:

Sub AAA()
Dim Destination As Range
Dim RowNumber As Long
Set Destination = Worksheets(2).Range("A1")
For RowNumber = 1 To 10 '<<<< CHANGE RowNumber as needed
If Len(Cells(RowNumber, "A").Text) > 0 Then
Rows(RowNumber).Copy Destination:=Destination
Set Destination = Destination(2, 1)
End If
Next RowNumber
End Sub

Change the row number from 1 to 10 to whatever rows you want to
process.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com




On Mon, 19 Apr 2010 09:25:01 -0700, Wes_A
<(E-Mail Removed)> wrote:

>I need to select from a range of rows - only those having data (formula
>result) in the first cell. There will be some rows without data in the first
>cell but they would contain a formula - these shoudl not be selected for copy.
>I want to select and copy all the rows having data in the first cell in
>order to paste these rows as values into a separate sheet in another workbook.
>Any suggestion?

 
Reply With Quote
 
michdenis
Guest
Posts: n/a
 
      19th Apr 2010
Hi,

For cells containing Text only

'---------------------------
Sub test()
Dim Rg As Range

On Error Resume Next
With Sheet1
With .Range("A1:A" & .Range("A65536").End(xlUp).Row)
Set Rg = .SpecialCells(xlCellTypeFormulas, xlTextValues)
End With
End With
Rg.EntireRow.Copy Sheet2.Range("A1")

End Sub
'---------------------------



"Wes_A" <(E-Mail Removed)> a écrit dans le message de groupe de discussion :
3E741A13-96B0-4CBA-9912-(E-Mail Removed)...
I need to select from a range of rows - only those having data (formula
result) in the first cell. There will be some rows without data in the first
cell but they would contain a formula - these shoudl not be selected for copy.
I want to select and copy all the rows having data in the first cell in
order to paste these rows as values into a separate sheet in another workbook.
Any suggestion?

 
Reply With Quote
 
michdenis
Guest
Posts: n/a
 
      19th Apr 2010
If you want Text and numerical stemming from formula

'-------------------------------
Sub test()
Dim Rg As Range

On Error Resume Next
With Sheet1
With .Range("A1:A" & .Range("A65536").End(xlUp).Row)
Set Rg = .SpecialCells(xlCellTypeFormulas, 3)
End With
End With
Rg.EntireRow.Copy Sheet2.Range("A1")

End Sub
'-------------------------------


"michdenis" <(E-Mail Removed)> a écrit dans le message de groupe de discussion :
095A9554-26C3-4F80-998A-(E-Mail Removed)...
Hi,

For cells containing Text only

'---------------------------
Sub test()
Dim Rg As Range

On Error Resume Next
With Sheet1
With .Range("A1:A" & .Range("A65536").End(xlUp).Row)
Set Rg = .SpecialCells(xlCellTypeFormulas, xlTextValues)
End With
End With
Rg.EntireRow.Copy Sheet2.Range("A1")

End Sub
'---------------------------



"Wes_A" <(E-Mail Removed)> a écrit dans le message de groupe de discussion :
3E741A13-96B0-4CBA-9912-(E-Mail Removed)...
I need to select from a range of rows - only those having data (formula
result) in the first cell. There will be some rows without data in the first
cell but they would contain a formula - these shoudl not be selected for copy.
I want to select and copy all the rows having data in the first cell in
order to paste these rows as values into a separate sheet in another workbook.
Any suggestion?

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      19th Apr 2010
It does not sound like you are looking for a code solution even though you
posted in a programming newsgroup. If that is the case, then assuming Column
A is your range's first cell's column, select Column A and click
Data/Filter/AutoFilter. You can now deselect the column and then click the
dropdown arrow that appeared in Cell A1... click "(NonBlanks)" from the list
that appears. You can now select the visible rows and copy/paste them
wherever you need them to be copied to. When you are done, just click
Data/Filter/AutoFilter again (you do not have to select the column this
time) to remove the filter and return your worksheet back to "normal".

--
Rick (MVP - Excel)



"Wes_A" <(E-Mail Removed)> wrote in message
news:3E741A13-96B0-4CBA-9912-(E-Mail Removed)...
> I need to select from a range of rows - only those having data (formula
> result) in the first cell. There will be some rows without data in the
> first
> cell but they would contain a formula - these shoudl not be selected for
> copy.
> I want to select and copy all the rows having data in the first cell in
> order to paste these rows as values into a separate sheet in another
> workbook.
> Any suggestion?


 
Reply With Quote
 
Jef Gorbach
Guest
Posts: n/a
 
      19th Apr 2010
This should give you a starting point.
It filters the range for those rows where column(a) isn't blank,
copies them to Sheet2, then removes those rows where column(a) = zero
(ie didn't have data). Obviously it would be more efficient if anyone
knows a way of filtering where column(a) has results so the second
filter would be unnecessary.

Sub FilterCopy()
Dim CopyRange As Range
'------ copy the rows with formulas within the range ---
Set CopyRange = Range("A2:C100")
CopyRange.AutoFilter field:=1, Criteria1:="<>"
CopyRange.SpecialCells(xlCellTypeVisible).Copy _
Destination:=Worksheets("Sheet2").Range("A2")
Cells.AutoFilter 'turn filter off
'------- now remove the zero fomula rows ------------------
Worksheets("Sheet2").Activate
Cells.AutoFilter field:=1, Criteria1:="0"
Cells.SpecialCells(xlCellTypeVisible).EntireRow.Delete
Cells.AutoFilter
Application.CutCopyMode = False
End Sub
 
Reply With Quote
 
Wes_A
Guest
Posts: n/a
 
      20th Apr 2010
Wow! Thank you folks for the different suggestions, I will try and see which
works best, but will keep all on record for future ref.
I find this forum so very helpful since I am no expert in programming, but
self taught. Thank you all so much for the recommendations.
Wes

"Wes_A" wrote:

> I need to select from a range of rows - only those having data (formula
> result) in the first cell. There will be some rows without data in the first
> cell but they would contain a formula - these shoudl not be selected for copy.
> I want to select and copy all the rows having data in the first cell in
> order to paste these rows as values into a separate sheet in another workbook.
> Any suggestion?

 
Reply With Quote
 
Wes_A
Guest
Posts: n/a
 
      20th Apr 2010
I triued the suggestion by Chip Pearson using the following code which seems
to be working:
Dim Destination As Range
Dim RowNumber As Long
Set Destination = Worksheets(2).Range("A1")
For RowNumber = 8 To 508
If Len(Cells(RowNumber, "A").Text) > 0 Then
Rows(RowNumber).Copy Destination:=Destination
Set Destination = Destination(2, 1)
End If
Next RowNumber

However, I need more help on this.
Firstly, I am wanting to copy into a specific sheet in a different Workbook,
not another sheet in the same one. (The destination Workbook will be one of
several others open at the same time.)
Secondly I want to paste "Values Onlly"
Thirdly, I want the data to the next row having no data in the first column
in the destination Workbook. i.e. to be added in rows below data previously
posted there by this macro.

I tried making changes to the code to achieve this but I guess it's beyond
my knowledge since it does not work.

Please assist.

"Wes_A" wrote:

> Wow! Thank you folks for the different suggestions, I will try and see which
> works best, but will keep all on record for future ref.
> I find this forum so very helpful since I am no expert in programming, but
> self taught. Thank you all so much for the recommendations.
> Wes
>
> "Wes_A" wrote:
>
> > I need to select from a range of rows - only those having data (formula
> > result) in the first cell. There will be some rows without data in the first
> > cell but they would contain a formula - these shoudl not be selected for copy.
> > I want to select and copy all the rows having data in the first cell in
> > order to paste these rows as values into a separate sheet in another workbook.
> > Any suggestion?

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy a range of cells 15 rows down and repeat to empty cell Mike V Microsoft Excel Programming 2 6th Jun 2008 01:48 PM
Read through Range and copy Cell data to Array missleigh Microsoft Excel Programming 1 13th Apr 2006 12:47 PM
Read through Range and copy Cell data to Array missleigh Microsoft Excel Programming 1 13th Apr 2006 12:00 AM
How to copy data in one cell into different rows catchxan Microsoft Excel Worksheet Functions 1 28th Nov 2005 01:25 AM
Access2000: Copy a range of rows to another range of rows using VBA Arvi Laanemets Microsoft Excel Worksheet Functions 1 10th May 2004 08:48 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:47 PM.