Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 692
Default Find & replace

Try this (code untested).
Caution it will error out if the value of cel is not found on Sheet1

Dim cel As Range

For Each cel In Sheets("Sheet2").Columns(1)
If Len(cel) 0 Then
cel.Value = WorksheetFunction.Index(Sheets("Sheet1").Columns(2 ), _
Match(cel, Sheets("Sheet1"), 0), 1)
ElseIf Len(cel) = 0 Then
Exit Sub
End If
End Sub

You can build a safeguard
if worksheetfunction.Countif(Sheets("Sheet1").Columns (1),cel)0 then

end if


--
steveB

Remove "AYN" from email to respond
wrote in message
ups.com...
Here is my little problem:

1st spreadsheet
===============

Column A | Column B
---------+----------
AAA(Tab) | 80001
BBB(Tab) | 80002
CCC(Tab) | 80003
XXX(Tab) | 80004
YYY(Tab) | 80005
ZZZ(Tab) | 80006

2nd spreadsheet
===============

Column A
--------
AAA
AAA
AAA
AAA
BBB
BBB
BBB
BBB
CCC
CCC
YYY
YYY
ZZZ
ZZZ
ZZZ
XXX
XXX

Expected result:
----------------

2nd spreadsheet
===============

Column A
--------
80001
80001
80001
80001
80002
80002
80002
80002
80003
80003
80005
80005
80006
80006
80006
80004
80004

I need to translate column A in the 2nd spreadsheet to numbers from the
1st spreadsheet (column B). I would appreciate any suggestion.

Regards,
koobel



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Find & replace

Dim cel As Range

Sub ConvertMaterialToId()

For Each cel In Worksheets("Sheet2").Columns(1)
If Len(cel) 0 Then
cel.Value =
WorksheetFunction.Index(Worksheets("Sheet1").Colum ns(2),
WorksheetFunction.Match(cel, Sheets("Sheet1"), 0), 1)
Else
If Len(cel) = 0 Then Exit Sub
End If
Next

End Sub

I get an error message "Subscript out of Range". What's wrong with that
piece of code?


STEVE BELL wrote:
Try this (code untested).
Caution it will error out if the value of cel is not found on Sheet1

Dim cel As Range

For Each cel In Sheets("Sheet2").Columns(1)
If Len(cel) 0 Then
cel.Value = WorksheetFunction.Index(Sheets("Sheet1").Columns(2 ), _
Match(cel, Sheets("Sheet1"), 0), 1)
ElseIf Len(cel) = 0 Then
Exit Sub
End If
End Sub

You can build a safeguard
if worksheetfunction.Countif(Sheets("Sheet1").Columns (1),cel)0 then

end if


--
steveB


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 692
Default Find & replace

First make sure you define the variable cel.

Replace Worksheets with Sheets.

Next replace "Sheet1" and "Sheet2" with the actual names of the worksheets -
"MySheet", "Data", "Master", "MyData" or what ever they are labled.
Worksheets("Sheet1"). becomes Sheets("MySheet").
[If the position of the worksheets will not change - you can use Sheets(1),
Sheets(2), etc
indicating the position of the worksheet in your workbook]
Worksheets("Sheet1"). becomes Sheets(1).

Make sure the the cel.value formula is one line - since it is very long I
have
used the line continuation " _" in the code below.

See if this works better. Let me know...


Sub ConvertMaterialToId()
Dim cel As Range
For Each cel In Sheets("Sheet2").Columns(1)
If Len(cel) 0 Then
cel.Value = WorksheetFunction.Index(Sheets("Sheet1").Columns(2 ), _
WorksheetFunction.Match(cel, Sheets("Sheet1"), 0), 1)
Else
If Len(cel) = 0 Then Exit Sub
End If
Next

End Sub


--
steveB

Remove "AYN" from email to respond
wrote in message
oups.com...
Dim cel As Range

Sub ConvertMaterialToId()

For Each cel In Worksheets("Sheet2").Columns(1)
If Len(cel) 0 Then
cel.Value =
WorksheetFunction.Index(Worksheets("Sheet1").Colum ns(2),
WorksheetFunction.Match(cel, Sheets("Sheet1"), 0), 1)
Else
If Len(cel) = 0 Then Exit Sub
End If
Next

End Sub

I get an error message "Subscript out of Range". What's wrong with that
piece of code?


STEVE BELL wrote:
Try this (code untested).
Caution it will error out if the value of cel is not found on Sheet1

Dim cel As Range

For Each cel In Sheets("Sheet2").Columns(1)
If Len(cel) 0 Then
cel.Value = WorksheetFunction.Index(Sheets("Sheet1").Columns(2 ),
_
Match(cel, Sheets("Sheet1"), 0), 1)
ElseIf Len(cel) = 0 Then
Exit Sub
End If
End Sub

You can build a safeguard
if worksheetfunction.Countif(Sheets("Sheet1").Columns (1),cel)0 then

end if


--
steveB




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Find & replace


"STEVE BELL" wrote in message
news:Gqzze.524$F96.263@trnddc08...
First make sure you define the variable cel.

Replace Worksheets with Sheets.


Why?


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 692
Default Find & replace

My bad...

cel had been defined...

and I just prefer Sheets... (because it is shorter)

Thanks for keeping me straight...

--
steveB

Remove "AYN" from email to respond
"Bob Phillips" wrote in message
...

"STEVE BELL" wrote in message
news:Gqzze.524$F96.263@trnddc08...
First make sure you define the variable cel.

Replace Worksheets with Sheets.


Why?






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Find & replace

Yeah but Sheets applies to all sheets, worksheets, charts etc., and you
can't have ranges in a chart.

--
HTH

Bob Phillips

"STEVE BELL" wrote in message
news:9QAze.632$Zy6.278@trnddc04...
My bad...

cel had been defined...

and I just prefer Sheets... (because it is shorter)

Thanks for keeping me straight...

--
steveB

Remove "AYN" from email to respond
"Bob Phillips" wrote in message
...

"STEVE BELL" wrote in message
news:Gqzze.524$F96.263@trnddc08...
First make sure you define the variable cel.

Replace Worksheets with Sheets.


Why?






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
Find & Replace: find part cell, replace whole cell katy Excel Worksheet Functions 3 April 3rd 23 01:20 PM
Find and Replace - Replace with Blank Space Studebaker Excel Discussion (Misc queries) 4 April 3rd 23 10:55 AM
Find and replace results can the appearance of find be different? LLS at DPW Excel Discussion (Misc queries) 2 October 26th 09 11:16 PM
where to put results of find operation in find and replace functio DEP Excel Worksheet Functions 5 November 15th 06 07:52 PM
find and replace - replace data in rows to separated by commas msdker Excel Worksheet Functions 1 April 15th 06 01:00 AM


All times are GMT +1. The time now is 06:39 AM.

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"