Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() "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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Find & Replace: find part cell, replace whole cell | Excel Worksheet Functions | |||
Find and Replace - Replace with Blank Space | Excel Discussion (Misc queries) | |||
Find and replace results can the appearance of find be different? | Excel Discussion (Misc queries) | |||
where to put results of find operation in find and replace functio | Excel Worksheet Functions | |||
find and replace - replace data in rows to separated by commas | Excel Worksheet Functions |