Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default More Find/REplace from table questions...

Hi again.
Thanks to Barry-Jon and Dave Peterson for their help earlier on this
topic. Now I need a little more help.

I have a macro I pieced together from this group that finds a value in
column 1 of a table in replaces it with it's corresponding value from
column 2, which works fantastically well.

Now I have one pesky column of data that has to match by 2 columns of
data. So essentially, if Columns C and D on worksheet1 match columns B
and C on worksheey2, I need to replace Column C on worksheet1 with
Colum A on worksheet2.

Does that make sense?

Here is the code I am working with for the single item matching
Find/Replace from a range:
______________________________________

Sub RangeFind2Replace1()

Dim rngReplaceWith As Excel.Range
Dim rngSearchArea As Excel.Range
Dim lngRepaceCount As Long

Set rngReplaceWith = GetUserRange("Please select find/replace
values range (two columns)")

If Not rngReplaceWith Is Nothing Then

'basic range size validation - a lot more could be done
If rngReplaceWith.Columns.Count = 2 Then

'now get the area in which to do the find/replace
Set rngSearchArea = GetUserRange("Please select the range
in which to find/replace")

If Not rngSearchArea Is Nothing Then

'do the search and replace
For lngRepaceCount = 1 To rngReplaceWith.Rows.Count

rngSearchArea.Replace
What:=rngReplaceWith.Cells(lngRepaceCount, 2).Value, _
Replacement:=rngReplaceWith.Cells(lngRepaceCount,
1).Value, _
MatchCase:=False, lookat:=xlWhole, ReplaceFormat:=False

Next lngRepaceCount

End If

Else

MsgBox "Invalid find/replace range selected", vbExclamation
+ vbOKOnly

End If

End If

End Sub

Private Function GetUserRange(Prompt As String, Optional Title As
String = "Input") As Excel.Range

On Error GoTo ErrorHandler

Dim retVal As Excel.Range

Set retVal = Application.InputBox(Prompt, Title, , , , , , 8)

ExitProc:
Set GetUserRange = retVal
Exit Function

ErrorHandler:
Set retVal = Nothing
Resume ExitProc

End Function

________________________________

Can this be modified to do what I need it to?

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 from table questions... [email protected] Excel Programming 0 June 19th 06 07:21 PM
Find/REplace from table questions... [email protected] Excel Programming 0 June 19th 06 06:55 PM
Find/REplace from table questions... [email protected] Excel Programming 2 June 14th 06 07:28 PM
Find/Replace from Table Steph Excel Programming 4 May 12th 06 07:05 PM
Find & Replace questions David Excel Worksheet Functions 1 November 2nd 04 06:41 PM


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