Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default comparing 2 worsheets using a macro

i need some help with macro. how do i compare names from b3:b50 of sheet1 to
complete listing of names(a1:a100) and employee id(b1:b100) of sheet2?
after finding a match it will output the employee id to a3:a50 of sheet1. if
it didn't find a match return blank.
ex. sheet 1 sheet 2
b3=alex a1=alex b1=001
output would be:
sheet 1
a3=001


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default comparing 2 worsheets using a macro

Give this a try:

Sub terranian()
Dim lr As Long, lr2 As Long
Dim c As Range, serRng As Range, f As Range
lr = Sheets(1).Cells(Rows.Count, 2).End(xlUp).Row
lr2 = Sheets(2).Cells(Rows.Count, 1).End(xlUp).Row
Set serRng = Sheets(2).Range("A1:A" & lr2)
For Each c In Sheets(1).Range("B3:B" & lr)
Set f = serRng.Find(c.Value, LookIn:=xlValues, _
MatchCase:=False)
If Not f Is Nothing Then
f.Offset(0, 1).Copy Sheets(1).Range("A" & c.Row)
End If
Next
End Sub

Copy this code to your standard VBA module. You might want to substitute
the sheets names for the index numbers that I used, unless they are in the
correct order as written.


"louie" wrote:

i need some help with macro. how do i compare names from b3:b50 of sheet1 to
complete listing of names(a1:a100) and employee id(b1:b100) of sheet2?
after finding a match it will output the employee id to a3:a50 of sheet1. if
it didn't find a match return blank.
ex. sheet 1 sheet 2
b3=alex a1=alex b1=001
output would be:
sheet 1
a3=001


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 do I combine many worsheets into one worksheet?? Teric506 Excel Discussion (Misc queries) 6 November 21st 07 05:00 PM
duplicating worsheets Don Excel Worksheet Functions 2 November 28th 06 07:11 PM
Linking 2 Worsheets Mike_C Links and Linking in Excel 3 August 10th 05 11:14 PM
Multiple worsheets DavidL Excel Programming 1 February 23rd 04 08:10 PM
Hidden Worsheets Shamsul Islam Excel Programming 1 February 16th 04 11:34 AM


All times are GMT +1. The time now is 04:09 PM.

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"