Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Lookup or Match

Worksheet 1 = Output
Worksheet 2 = Lookup
I want to ensure that the names in worksheet 1 are the same as worksheet 2.
Is there any code to do this

"crazybass2" wrote:

I am not clear as to what you have/want....what I think you have is 2
workbooks, one with sheet names "Fred Bloggs" and "Richard Smith" and
another workbook with sheet names "Mr Fred Harry Bloggs" and "Mr Richard John
Smith" and you want the second workbooks sheet names to match the first. Is
this correct?

If this is the case, is it always the same pattern (ie. remove the prefix
and the middle name)?

Mike
"mhd143" wrote:

Not sure how to go about this, but what i'm trying to do is that from an
output worksheet i want to ensure the names column matches the lookup
worksheet names. I then want the names in the output worksheet replaced with
the entry from the lookup worksheet.

OUTPUT(before)
Mr Fred Harry Bloggs
Mr Richard John Smith

LOOKUP
Fred Bloggs
Richard Smith

OUTPUT(after)
Fred Bloggs
Richard Smith

Thanks


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 167
Default Lookup or Match

Insert the following code into a module in the template workbook (the book
with the sheet titles you want). I put a measure in the code to handle
multiple sheets for the same name (ie. Mr Fred Bloggs and Mr Fred Harry
Bloggs). If you don't want it use the second code below.

Mike

Option Explicit
Sub UpdateSheetNames()
Dim This As Workbook, That As Workbook
Dim shthis As Worksheet, shthat As Worksheet, ws As Worksheet
Dim first As String, last As String
Dim i As Integer
Set This = ThisWorkbook
Set That = Workbooks.Open("P:\Excel Help\MatchSheets2.xls")
For Each shthis In This.Worksheets
i = 1
first = Left(shthis.Name, InStr(1, shthis.Name, " ") - 1)
last = Right(shthis.Name, Len(shthis.Name) - _
InStr(1, shthis.Name, " "))
For Each shthat In That.Worksheets
If InStr(1, shthat.Name, first) < 0 And _
InStr(1, shthat.Name, last) < 0 And _
InStr(1, shthat.Name, first) < InStr(1, shthat.Name, last) Then
On Error Resume Next
MsgBox (first & " " & last)
Set ws = That.Sheets(first & " " & last)
On Error GoTo 0
If ws Is Nothing Then
shthat.Name = shthis.Name
Else
shthat.Name = shthis.Name & i
i = i + 1
Set ws = Nothing
End If
End If
Next shthat
Next shthis
End Sub

'****** END OF CODE ******


'**** SECOND CODE ****
Option Explicit
Sub UpdateSheetNames()
Dim This As Workbook, That As Workbook
Dim shthis As Worksheet, shthat As Worksheet, ws As Worksheet
Dim first As String, last As String
Dim i As Integer
Set This = ThisWorkbook
Set That = Workbooks.Open("P:\Excel Help\MatchSheets2.xls")
For Each shthis In This.Worksheets
i = 1
first = Left(shthis.Name, InStr(1, shthis.Name, " ") - 1)
last = Right(shthis.Name, Len(shthis.Name) - _
InStr(1, shthis.Name, " "))
For Each shthat In That.Worksheets
If InStr(1, shthat.Name, first) < 0 And _
InStr(1, shthat.Name, last) < 0 And _
InStr(1, shthat.Name, first) < InStr(1, shthat.Name, last) Then
shthat.Name = shthis.Name
End If
End If
Next shthat
Next shthis
End Sub

'****** END OF CODE ******


"mhd143" wrote:

Worksheet 1 = Output
Worksheet 2 = Lookup
I want to ensure that the names in worksheet 1 are the same as worksheet 2.
Is there any code to do this

"crazybass2" wrote:

I am not clear as to what you have/want....what I think you have is 2
workbooks, one with sheet names "Fred Bloggs" and "Richard Smith" and
another workbook with sheet names "Mr Fred Harry Bloggs" and "Mr Richard John
Smith" and you want the second workbooks sheet names to match the first. Is
this correct?

If this is the case, is it always the same pattern (ie. remove the prefix
and the middle name)?

Mike
"mhd143" wrote:

Not sure how to go about this, but what i'm trying to do is that from an
output worksheet i want to ensure the names column matches the lookup
worksheet names. I then want the names in the output worksheet replaced with
the entry from the lookup worksheet.

OUTPUT(before)
Mr Fred Harry Bloggs
Mr Richard John Smith

LOOKUP
Fred Bloggs
Richard Smith

OUTPUT(after)
Fred Bloggs
Richard Smith

Thanks


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
H and V lookup or match? excelrookie Excel Worksheet Functions 2 April 7th 10 12:40 AM
Lookup Formula: Return 1st match, then 2nd match, then 3rd match Scott Excel Discussion (Misc queries) 4 December 11th 09 05:50 AM
LookUp/Match carl Excel Worksheet Functions 5 December 19th 07 11:28 PM
Lookup? Match? pulling rows from one spreadsheet to match a text f cjax Excel Worksheet Functions 3 July 21st 06 02:51 PM
match or lookup? Dave Excel Worksheet Functions 1 December 8th 04 07:52 AM


All times are GMT +1. The time now is 11:22 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"