PC Review


Reply
Thread Tools Rate Thread

Compare 2 sheets and copy matching data

 
 
Sarah
Guest
Posts: n/a
 
      29th Jun 2007
I have 2 sheets: Agents and Production. I want to compare the data in
column B of Agents to column B of Production. If the value from Agents
matches a row in Production, I want to copy the value from column O of
that row of Production to another worksheet (Count). It's been a while
since I've done any VBA programming, and I was never very good at it
to begin with. Can anyone help me?

Sarah

 
Reply With Quote
 
 
 
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      29th Jun 2007
copy the values of sheet Production, Column B to column A of Count

in column B of Count put the formula
B2:
=if(countif(Agents!$B:$B,A2)>0,Production!O2,"")

then drag fill down the column.

--
Regards,
Tom Ogilvy



"Sarah" wrote:

> I have 2 sheets: Agents and Production. I want to compare the data in
> column B of Agents to column B of Production. If the value from Agents
> matches a row in Production, I want to copy the value from column O of
> that row of Production to another worksheet (Count). It's been a while
> since I've done any VBA programming, and I was never very good at it
> to begin with. Can anyone help me?
>
> Sarah
>
>

 
Reply With Quote
 
=?Utf-8?B?QUtwaGlkZWx0?=
Guest
Posts: n/a
 
      29th Jun 2007
I just threw this together. Try it out, mess with it for your needs.

Sub test()
Dim sht1 As Worksheet, sht2 As Worksheet, sht3 As Worksheet
Dim cnt1 As Integer, x As Integer

Set sht1 = Worksheets("Agents")
Set sht2 = Worksheets("Production")
Set sht3 = Worksheets("Count")

sht1.Activate

cnt1 = sht1.Range(Range("B1"), Range("B1").End(xlDown)).Count

Range("B1").Activate
For x = 1 To cnt1
If sht1.Range("B1").Offset(x, 0).Value = sht2.Range("B1").Offset(x,
0).Value Then
sht1.Range("B1").Offset(x, 13).Copy
sht3.Range("B65536").End(xlUp).Offset(1, 0).PasteSpecial
(xlPasteValues)
End If
Next x

End Sub

"Sarah" wrote:

> I have 2 sheets: Agents and Production. I want to compare the data in
> column B of Agents to column B of Production. If the value from Agents
> matches a row in Production, I want to copy the value from column O of
> that row of Production to another worksheet (Count). It's been a while
> since I've done any VBA programming, and I was never very good at it
> to begin with. Can anyone help me?
>
> Sarah
>
>

 
Reply With Quote
 
Sarah
Guest
Posts: n/a
 
      18th Jul 2007
On Jun 29, 11:12 am, AKphidelt <AKphid...@discussions.microsoft.com>
wrote:
> I just threw this together. Try it out, mess with it for your needs.
>
> Sub test()
> Dim sht1 As Worksheet, sht2 As Worksheet, sht3 As Worksheet
> Dim cnt1 As Integer, x As Integer
>
> Set sht1 = Worksheets("Agents")
> Set sht2 = Worksheets("Production")
> Set sht3 = Worksheets("Count")
>
> sht1.Activate
>
> cnt1 = sht1.Range(Range("B1"), Range("B1").End(xlDown)).Count
>
> Range("B1").Activate
> For x = 1 To cnt1
> If sht1.Range("B1").Offset(x, 0).Value = sht2.Range("B1").Offset(x,
> 0).Value Then
> sht1.Range("B1").Offset(x, 13).Copy
> sht3.Range("B65536").End(xlUp).Offset(1, 0).PasteSpecial
> (xlPasteValues)
> End If
> Next x
>
> End Sub
>

Okay, maybe I just don't understand the code, but this doesn't seem to
copy the value from sheet Production to sheet Count in the row on
Production that matches a value on Agents.

I have Agent numbers on the Agent sheet in column B.
I have production reporting on the Production sheet. The column with
the agent numbers here is also B. The column with the policy count in
which I'm interested varies (unfortunately), but I could manually
paste it into column C.

I want this code to match values from column B of Agent to column B of
Production. When the matching row is located, I want it to copy the
value from that row of column C of Production to sheet Count (column A
would be fine).

 
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
Compare worksheets to copy and paste data based on matching criter Monomeeth Microsoft Excel Programming 1 4th Nov 2008 04:50 AM
compare contents between sheets and identify matching values nanda Microsoft Excel Programming 1 3rd Nov 2007 12:12 PM
Compare two wk sheets with common data using copy paste macro =?Utf-8?B?Y29uZWpv?= Microsoft Excel Worksheet Functions 0 8th Oct 2007 09:21 AM
how to compare two columns on two sheets and copy associated data from one sheet to the other? meghantrus@hotmail.com Microsoft Excel Programming 1 22nd Jun 2007 04:12 PM
how to compare two columns on two sheets and copy associated data from one sheet to the other? meghantrus@hotmail.com Microsoft Excel Worksheet Functions 2 22nd Jun 2007 03:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:01 AM.