![]() |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
Copy rows where entry in column A
Ha ha. Can't comment on the first point (let's just say it's relative).
On point 2 - I agree Joel's solution looks much neater but (pardon me if I'm wrong, as I'm not a coder) it does not appear to make the test for 'where there's a value in column A'. probably quite easy to add that though. Point 3 - Google has God status does it not? Take a look...they seem to think it's today. cheers James "Mike H" wrote: 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 |
Copy rows where entry in column A
I'm not a genius. The 247th St Patrick Day parade is going to start today in
NYC marching down 5th avenue like normal on the 17th Of March. "Mike H" wrote: 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 |
Copy rows where entry in column A
Thanks Joel - sounds pretty conclusive...
"Joel" wrote: I'm not a genius. The 247th St Patrick Day parade is going to start today in NYC marching down 5th avenue like normal on the 17th Of March. "Mike H" wrote: 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 |
All times are GMT +1. The time now is 02:11 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com