View Single Post
  #3   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions
AltaEgo AltaEgo is offline
external usenet poster
 
Posts: 245
Default How to check the whole column at the same time?

If you mean replace all instances of Father with 1; Mother with 2, Sister
with 3, try the following:


Option Base 1

Sub ChangeStrToNum()


Dim FindArr, ReplArr

FindArr = Array("Father", "Mother", "Sister")
ReplArr = Array(1, 2, 3)

'To undo
'ReplArr = Array("Father", "Mother", "Sister")
'FindArr = Array(1, 2, 3)

Range("yourRange").Activate 'change
If UBound(FindArr) = UBound(ReplArr) Then
For i = 1 To UBound(FindArr)

Selection.Replace What:=FindArr(i), Replacement:=ReplArr(i),
LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

Next i
Else

MsgBox "Your arrays contain different numbers of elements"
End If
End Sub

--
Steve

"tlee" wrote in message
...
Hi all,

Could anyone help me how to check the column content by different
condition?

If the content of the cell is "Father" then replace it to "1" in the same
column.
If the content of the other cell is "Mother" then replace it to "2" in
same column.
If the content of another cell is "Sister" then replace it to "3" in the
same column.

Besides, how can I implement this checking by using Marco?

Thanks,
Tlee