Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Copy rows where entry in column A

Hi

I wish to copy only rows where there is an entry in column A. For those
rows, I wish to copy the entire row (values only) to another sheet.

tia
James
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Copy rows where entry in column A

Just to modify this - the test for column A only needs to extend from row 2
to row 100. So if, in those set of rows, there is a value in column A then
copy the antire row (values only) to another sheet.

James

"access user" wrote:

Hi

I wish to copy only rows where there is an entry in column A. For those
rows, I wish to copy the entire row (values only) to another sheet.

tia
James

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Copy rows where entry in column A

Alt + F11 to open VB editor. Right click 'This workbook' and insert module.
Paste this in and run it

Sub stance()
Dim myrange, copyrange As Range
Sheets("Sheet1").Select
Set myrange = Range("A2:A100")
For Each c In myrange
If c.Value < "" Then
If copyrange Is Nothing Then
Set copyrange = c.EntireRow
Else
Set copyrange = Union(copyrange, c.EntireRow)
End If

End If
Next
copyrange.Copy
Sheets("Sheet2").Select 'Change to suit
Cells(1, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues
End Sub

Did that work?

Mike

"access user" wrote:

Hi

I wish to copy only rows where there is an entry in column A. For those
rows, I wish to copy the entire row (values only) to another sheet.

tia
James

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Copy rows where entry in column A

Hi

I get 'object variable or With block variable not set error'

on line copyrange.copy

tia
James

"Mike H" wrote:

Alt + F11 to open VB editor. Right click 'This workbook' and insert module.
Paste this in and run it

Sub stance()
Dim myrange, copyrange As Range
Sheets("Sheet1").Select
Set myrange = Range("A2:A100")
For Each c In myrange
If c.Value < "" Then
If copyrange Is Nothing Then
Set copyrange = c.EntireRow
Else
Set copyrange = Union(copyrange, c.EntireRow)
End If

End If
Next
copyrange.Copy
Sheets("Sheet2").Select 'Change to suit
Cells(1, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues
End Sub

Did that work?

Mike

"access user" wrote:

Hi

I wish to copy only rows where there is an entry in column A. For those
rows, I wish to copy the entire row (values only) to another sheet.

tia
James

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Copy rows where entry in column A

Thats because it's not finding any cells with data in so there is nothing for
it to copy. I never bothered to trap for that becuase I assumed incorrectly
there would always be something. You can trap for that with

If Not copyrange Is Nothing Then
copyrange.Copy
Else
Exit Sub
End If

Mike


"access user" wrote:

Hi

I get 'object variable or With block variable not set error'

on line copyrange.copy

tia
James

"Mike H" wrote:

Alt + F11 to open VB editor. Right click 'This workbook' and insert module.
Paste this in and run it

Sub stance()
Dim myrange, copyrange As Range
Sheets("Sheet1").Select
Set myrange = Range("A2:A100")
For Each c In myrange
If c.Value < "" Then
If copyrange Is Nothing Then
Set copyrange = c.EntireRow
Else
Set copyrange = Union(copyrange, c.EntireRow)
End If

End If
Next
copyrange.Copy
Sheets("Sheet2").Select 'Change to suit
Cells(1, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues
End Sub

Did that work?

Mike

"access user" wrote:

Hi

I wish to copy only rows where there is an entry in column A. For those
rows, I wish to copy the entire row (values only) to another sheet.

tia
James



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Copy rows where entry in column A

You deserve a pint of Guiness because you are 'pure Genius' and it's St
Patrick's Day. Thanks a lot.
James

"Mike H" wrote:

Thats because it's not finding any cells with data in so there is nothing for
it to copy. I never bothered to trap for that becuase I assumed incorrectly
there would always be something. You can trap for that with

If Not copyrange Is Nothing Then
copyrange.Copy
Else
Exit Sub
End If

Mike


"access user" wrote:

Hi

I get 'object variable or With block variable not set error'

on line copyrange.copy

tia
James

"Mike H" wrote:

Alt + F11 to open VB editor. Right click 'This workbook' and insert module.
Paste this in and run it

Sub stance()
Dim myrange, copyrange As Range
Sheets("Sheet1").Select
Set myrange = Range("A2:A100")
For Each c In myrange
If c.Value < "" Then
If copyrange Is Nothing Then
Set copyrange = c.EntireRow
Else
Set copyrange = Union(copyrange, c.EntireRow)
End If

End If
Next
copyrange.Copy
Sheets("Sheet2").Select 'Change to suit
Cells(1, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues
End Sub

Did that work?

Mike

"access user" wrote:

Hi

I wish to copy only rows where there is an entry in column A. For those
rows, I wish to copy the entire row (values only) to another sheet.

tia
James

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Copy rows where entry in column A

Thank's for that but three small points:-

I'm not a genius far from it.
Joel's solution is better than mine
I'm not going to enter the debate about when St Patricks day is this year
because the Pope seems to have quite strong views in the matter<g

Mike

"access user" wrote:

You deserve a pint of Guiness because you are 'pure Genius' and it's St
Patrick's Day. Thanks a lot.
James

"Mike H" wrote:

Thats because it's not finding any cells with data in so there is nothing for
it to copy. I never bothered to trap for that becuase I assumed incorrectly
there would always be something. You can trap for that with

If Not copyrange Is Nothing Then
copyrange.Copy
Else
Exit Sub
End If

Mike


"access user" wrote:

Hi

I get 'object variable or With block variable not set error'

on line copyrange.copy

tia
James

"Mike H" wrote:

Alt + F11 to open VB editor. Right click 'This workbook' and insert module.
Paste this in and run it

Sub stance()
Dim myrange, copyrange As Range
Sheets("Sheet1").Select
Set myrange = Range("A2:A100")
For Each c In myrange
If c.Value < "" Then
If copyrange Is Nothing Then
Set copyrange = c.EntireRow
Else
Set copyrange = Union(copyrange, c.EntireRow)
End If

End If
Next
copyrange.Copy
Sheets("Sheet2").Select 'Change to suit
Cells(1, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues
End Sub

Did that work?

Mike

"access user" wrote:

Hi

I wish to copy only rows where there is an entry in column A. For those
rows, I wish to copy the entire row (values only) to another sheet.

tia
James

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Copy rows where entry in column A

Your original request

Sheets("Sheet1").Cells.SpecialCells(xlTextValues). EntireRow.Copy
Sheets("Sheet2").Cells.PasteSpecial Paste:=xlPasteValues


fror a limited range
Sheets("Sheet1").Range("A1:A100").SpecialCells(xlT extValues).EntireRow.Copy
Sheets("Sheet2").Cells.PasteSpecial Paste:=xlPasteValues


"access user" wrote:

Hi

I wish to copy only rows where there is an entry in column A. For those
rows, I wish to copy the entire row (values only) to another sheet.

tia
James

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Copy rows where entry in column A

Thanks Joel, Mike H got there first. Appreciate your response though.
James

"access user" wrote:

Hi

I wish to copy only rows where there is an entry in column A. For those
rows, I wish to copy the entire row (values only) to another sheet.

tia
James

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 last entry of column to bottom of column jimmy_v_12 Excel Worksheet Functions 4 October 29th 09 08:53 PM
Excel: How copy all rows that have a given column entry? Motown Mick Excel Discussion (Misc queries) 20 June 12th 07 06:56 PM
copy value of cell from last entry in column Jay Trull Excel Worksheet Functions 1 April 23rd 06 03:10 AM
Auto-copy the last entry in a column to a new cell George F Excel Worksheet Functions 2 November 18th 05 07:36 PM
Insert rows depending on entry in certain column Gareth[_3_] Excel Programming 1 December 12th 03 03:24 AM


All times are GMT +1. The time now is 07:06 AM.

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"