Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
kwl kwl is offline
external usenet poster
 
Posts: 2
Default Compare and copy dose nothing

Can someone point me in the right direction, I can get this to work
when I copy the entire row but I only want to copy a single cell to a
cell on the main page. Sheet1 is used as a part list with prices.

Sub copyData()
Dim rng1 As Range, rng2 As Range
Dim cell As Range, rw As Long
Dim sh As Worksheet
With Worksheets("Sheet1")
Set rng1 = .Range(.Cells(1, "A"), .Cells(.Rows.Count,
"A").End(xlUp))
End With
With Worksheets("node 1&2")
Set rng2 = .Range(.Cells(1, "B"), .Cells(.Rows.Count,
"B").End(xlUp))
End With
rw = 1
For Each cell In rng2
If cell.Value = rng1.Cells(Rows.Count, "A").Value Then
rng1.Cells(Rows.Count, "E").Copy Destination:=rng2.Cells(Rows.Count,
"E")
rw = rw + 1
End If
Next
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
kwl kwl is offline
external usenet poster
 
Posts: 2
Default Compare and copy dose nothing

Any help at all?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Compare and copy dose nothing

I'm not sure what you're doing.

Are you trying to look for a match for each cell in rng2 and then copy the value
in column E to the matching row in sheet1?

If yes, maybe....

Option Explicit
Sub copyData()
Dim Rng1 As Range
Dim Rng2 As Range
Dim myCell As Range
Dim res As Variant

With Worksheets("Sheet1")
Set Rng1 = .Range(.Cells(1, "A"), .Cells(.Rows.Count, "A").End(xlUp))
End With

With Worksheets("node 1&2")
Set Rng2 = .Range(.Cells(1, "B"), .Cells(.Rows.Count, "B").End(xlUp))
End With

For Each myCell In Rng2.Cells
res = Application.Match(myCell.Value, Rng1, 0)
If IsError(res) Then
'no matching value
Else
myCell.Offset(0, 3).Copy _
Destination:=Rng1(res).Offset(0, 4)
End If
Next myCell

End Sub

But I'm really not sure if I copied the right cell--since one sheet has the key
in column A and the other in column B.

You may have to fiddle with this line:

myCell.Offset(0, 3).Copy _
Destination:=Rng1(res).Offset(0, 4)

..offset(0,3) from column B gives me column E.
..offset(0,4) from column A gives me column E.

kwl wrote:

Can someone point me in the right direction, I can get this to work
when I copy the entire row but I only want to copy a single cell to a
cell on the main page. Sheet1 is used as a part list with prices.

Sub copyData()
Dim rng1 As Range, rng2 As Range
Dim cell As Range, rw As Long
Dim sh As Worksheet
With Worksheets("Sheet1")
Set rng1 = .Range(.Cells(1, "A"), .Cells(.Rows.Count,
"A").End(xlUp))
End With
With Worksheets("node 1&2")
Set rng2 = .Range(.Cells(1, "B"), .Cells(.Rows.Count,
"B").End(xlUp))
End With
rw = 1
For Each cell In rng2
If cell.Value = rng1.Cells(Rows.Count, "A").Value Then
rng1.Cells(Rows.Count, "E").Copy Destination:=rng2.Cells(Rows.Count,
"E")
rw = rw + 1
End If
Next
End Sub


--

Dave Peterson
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
how dose filter works to last cell in the column Khalid Excel Discussion (Misc queries) 2 April 29th 10 01:03 PM
excel file dose not open ERROR Excel Discussion (Misc queries) 0 September 28th 06 10:43 AM
why dose excel return invalid web query Barry Excel Discussion (Misc queries) 0 February 25th 06 10:07 PM
options under tools dose not come up Tracy Excel Worksheet Functions 3 September 15th 05 09:33 PM
How can I estimate EC50 in a dose-response graph? Charis Charts and Charting in Excel 2 January 23rd 05 02:55 PM


All times are GMT +1. The time now is 08:31 AM.

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"