Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 83
Default Copy/Paste Problem

Hi Folks,

I have a bunch of data in columns D & E on a sheet named "Compare". Column
D is full of VLOOKUP formulas some of which result in a #N/A error. I would
like to copy and paste the contents columns D & E for any row where column
D's formula results in #N/A. My list runs from row 6 to row 300 and I only
want to return the offending #N/A rows and paste their contents from columns
D & E to columns A & B on a sheet named "Results".

Can this be done in a macro?

Thanks in Advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Copy/Paste Problem

Stephen,

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

Sub sidence()
Dim MyRange, MyRange1 As Range
Sheets("Compare").Select
lastrow = Sheets("Compare").Cells(Rows.Count, "D").End(xlUp).Row
Set MyRange = Sheets("Compare").Range("D1:D" & lastrow)
For Each c In MyRange
If c.Text = "#N/A" Then
If MyRange1 Is Nothing Then
Set MyRange1 = c.Resize(, 2)
Else
Set MyRange1 = Union(MyRange1, c.Resize(, 2))
End If
End If
Next

If Not MyRange1 Is Nothing Then
MyRange1.Copy
Sheets("results").Select
Range("A1").Select
ActiveSheet.Paste
End If
End Sub

Mike
"Stephen" wrote:

Hi Folks,

I have a bunch of data in columns D & E on a sheet named "Compare". Column
D is full of VLOOKUP formulas some of which result in a #N/A error. I would
like to copy and paste the contents columns D & E for any row where column
D's formula results in #N/A. My list runs from row 6 to row 300 and I only
want to return the offending #N/A rows and paste their contents from columns
D & E to columns A & B on a sheet named "Results".

Can this be done in a macro?

Thanks in Advance.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 83
Default Copy/Paste Problem

Wow, pretty good stuff. Worked like a charm.

Not to be a pest but do you have one that will compare values in Column "G"
on the "Compare" sheet, with the values in Column "A" on the "Compare" sheet,
and return the row values from Columns G & H to the "Results" sheet in
columns D & E?

"Mike H" wrote:

Stephen,

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

Sub sidence()
Dim MyRange, MyRange1 As Range
Sheets("Compare").Select
lastrow = Sheets("Compare").Cells(Rows.Count, "D").End(xlUp).Row
Set MyRange = Sheets("Compare").Range("D1:D" & lastrow)
For Each c In MyRange
If c.Text = "#N/A" Then
If MyRange1 Is Nothing Then
Set MyRange1 = c.Resize(, 2)
Else
Set MyRange1 = Union(MyRange1, c.Resize(, 2))
End If
End If
Next

If Not MyRange1 Is Nothing Then
MyRange1.Copy
Sheets("results").Select
Range("A1").Select
ActiveSheet.Paste
End If
End Sub

Mike
"Stephen" wrote:

Hi Folks,

I have a bunch of data in columns D & E on a sheet named "Compare". Column
D is full of VLOOKUP formulas some of which result in a #N/A error. I would
like to copy and paste the contents columns D & E for any row where column
D's formula results in #N/A. My list runs from row 6 to row 300 and I only
want to return the offending #N/A rows and paste their contents from columns
D & E to columns A & B on a sheet named "Results".

Can this be done in a macro?

Thanks in Advance.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Copy/Paste Problem

Stephen,

You didn't actually tell me what I was comparing in columns G&A so this
copies them if they are the same

Sub Not_To_Be_A_Pest()
Dim MyRange, MyRange1 As Range
Sheets("Compare").Select
lastrow = Sheets("Compare").Cells(Rows.Count, "G").End(xlUp).Row
Set MyRange = Sheets("Compare").Range("G1:G" & lastrow)
For Each c In MyRange
If c.Value = c.Offset(0, -6).Value Then
If MyRange1 Is Nothing Then
Set MyRange1 = c.Resize(, 2)
Else
Set MyRange1 = Union(MyRange1, c.Resize(, 2))
End If
End If
Next

If Not MyRange1 Is Nothing Then
MyRange1.Copy

Sheets("results").Select
Range("D1").Select
ActiveSheet.PasteSpecial
End If
End Sub


Mike

"Stephen" wrote:

Wow, pretty good stuff. Worked like a charm.

Not to be a pest but do you have one that will compare values in Column "G"
on the "Compare" sheet, with the values in Column "A" on the "Compare" sheet,
and return the row values from Columns G & H to the "Results" sheet in
columns D & E?

"Mike H" wrote:

Stephen,

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

Sub sidence()
Dim MyRange, MyRange1 As Range
Sheets("Compare").Select
lastrow = Sheets("Compare").Cells(Rows.Count, "D").End(xlUp).Row
Set MyRange = Sheets("Compare").Range("D1:D" & lastrow)
For Each c In MyRange
If c.Text = "#N/A" Then
If MyRange1 Is Nothing Then
Set MyRange1 = c.Resize(, 2)
Else
Set MyRange1 = Union(MyRange1, c.Resize(, 2))
End If
End If
Next

If Not MyRange1 Is Nothing Then
MyRange1.Copy
Sheets("results").Select
Range("A1").Select
ActiveSheet.Paste
End If
End Sub

Mike
"Stephen" wrote:

Hi Folks,

I have a bunch of data in columns D & E on a sheet named "Compare". Column
D is full of VLOOKUP formulas some of which result in a #N/A error. I would
like to copy and paste the contents columns D & E for any row where column
D's formula results in #N/A. My list runs from row 6 to row 300 and I only
want to return the offending #N/A rows and paste their contents from columns
D & E to columns A & B on a sheet named "Results".

Can this be done in a macro?

Thanks in Advance.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default Copy/Paste Problem

For i = 5 To 300
Set curCell = Worksheets("Sheet2").Cells(i, 4)
If curCell.Text = "#N/A" Then
lastrow = Worksheets("Sheet1").Cells(Rows.Count,
1).End(xlUp).Offset(1, 0).Row
Worksheets("Sheet1").Range("A" & lastrow).Value = curCell
Worksheets("Sheet1").Range("B" & lastrow).Value = curCell.Offset(0, 1)
End If
Next i

"Stephen" wrote:

Hi Folks,

I have a bunch of data in columns D & E on a sheet named "Compare". Column
D is full of VLOOKUP formulas some of which result in a #N/A error. I would
like to copy and paste the contents columns D & E for any row where column
D's formula results in #N/A. My list runs from row 6 to row 300 and I only
want to return the offending #N/A rows and paste their contents from columns
D & E to columns A & B on a sheet named "Results".

Can this be done in a macro?

Thanks in Advance.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default Copy/Paste Problem

Forgot to change sheet names
For i = 5 To 300
Set curCell = Worksheets("Compare").Cells(i, 4)
If curCell.Text = "#N/A" Then
lastrow = Worksheets("Results").Cells(Rows.Count,
1).End(xlUp).Offset(1, 0).Row
Worksheets("Results").Range("A" & lastrow).Value = curCell
Worksheets("Results").Range("B" & lastrow).Value = curCell.Offset(0,
1)
End If
Next i
"Mike" wrote:

For i = 5 To 300
Set curCell = Worksheets("Sheet2").Cells(i, 4)
If curCell.Text = "#N/A" Then
lastrow = Worksheets("Sheet1").Cells(Rows.Count,
1).End(xlUp).Offset(1, 0).Row
Worksheets("Sheet1").Range("A" & lastrow).Value = curCell
Worksheets("Sheet1").Range("B" & lastrow).Value = curCell.Offset(0, 1)
End If
Next i

"Stephen" wrote:

Hi Folks,

I have a bunch of data in columns D & E on a sheet named "Compare". Column
D is full of VLOOKUP formulas some of which result in a #N/A error. I would
like to copy and paste the contents columns D & E for any row where column
D's formula results in #N/A. My list runs from row 6 to row 300 and I only
want to return the offending #N/A rows and paste their contents from columns
D & E to columns A & B on a sheet named "Results".

Can this be done in a macro?

Thanks in Advance.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 83
Default Copy/Paste Problem

My appologies, I'm not making myself clear.

Actually it's two seperate problems I'm trying to tackle. From the first
list in Columns D & E I'm wanting to return all #N/A values. From the second
list in columns G & H, I want to compare values in column H against values in
column D and return the values from (rows) from columns G & H where the
column H vlue does not appear in the column D values.



"Mike H" wrote:

Stephen,

You didn't actually tell me what I was comparing in columns G&A so this
copies them if they are the same

Sub Not_To_Be_A_Pest()
Dim MyRange, MyRange1 As Range
Sheets("Compare").Select
lastrow = Sheets("Compare").Cells(Rows.Count, "G").End(xlUp).Row
Set MyRange = Sheets("Compare").Range("G1:G" & lastrow)
For Each c In MyRange
If c.Value = c.Offset(0, -6).Value Then
If MyRange1 Is Nothing Then
Set MyRange1 = c.Resize(, 2)
Else
Set MyRange1 = Union(MyRange1, c.Resize(, 2))
End If
End If
Next

If Not MyRange1 Is Nothing Then
MyRange1.Copy

Sheets("results").Select
Range("D1").Select
ActiveSheet.PasteSpecial
End If
End Sub


Mike

"Stephen" wrote:

Wow, pretty good stuff. Worked like a charm.

Not to be a pest but do you have one that will compare values in Column "G"
on the "Compare" sheet, with the values in Column "A" on the "Compare" sheet,
and return the row values from Columns G & H to the "Results" sheet in
columns D & E?

"Mike H" wrote:

Stephen,

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

Sub sidence()
Dim MyRange, MyRange1 As Range
Sheets("Compare").Select
lastrow = Sheets("Compare").Cells(Rows.Count, "D").End(xlUp).Row
Set MyRange = Sheets("Compare").Range("D1:D" & lastrow)
For Each c In MyRange
If c.Text = "#N/A" Then
If MyRange1 Is Nothing Then
Set MyRange1 = c.Resize(, 2)
Else
Set MyRange1 = Union(MyRange1, c.Resize(, 2))
End If
End If
Next

If Not MyRange1 Is Nothing Then
MyRange1.Copy
Sheets("results").Select
Range("A1").Select
ActiveSheet.Paste
End If
End Sub

Mike
"Stephen" wrote:

Hi Folks,

I have a bunch of data in columns D & E on a sheet named "Compare". Column
D is full of VLOOKUP formulas some of which result in a #N/A error. I would
like to copy and paste the contents columns D & E for any row where column
D's formula results in #N/A. My list runs from row 6 to row 300 and I only
want to return the offending #N/A rows and paste their contents from columns
D & E to columns A & B on a sheet named "Results".

Can this be done in a macro?

Thanks in Advance.

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
problem with copy and paste Tomek Excel Discussion (Misc queries) 2 February 7th 09 12:49 PM
Copy Paste problem Ian_Add Excel Discussion (Misc queries) 3 January 11th 08 02:47 PM
copy paste problem? Neil22 Excel Discussion (Misc queries) 5 January 10th 06 05:32 PM
VBA Copy Paste Problem Richard Slacum Excel Programming 5 December 29th 05 07:10 PM
Excel cut/Paste Problem: Year changes after data is copy and paste Asif Excel Discussion (Misc queries) 2 December 9th 05 05:16 PM


All times are GMT +1. The time now is 12:15 PM.

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"