LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel Find and Replace Problem with Array

Hi,

I'm trying to write a small utility to convert names of days and months from
English to another language.

I have a form with four multi-line text boxes (FromMonth, FromDay, ToMonth,
ToDay), a "Translate" button and a "Cancel" button.

The English months & days are populated in the From textboxes and I want to
be able to paste the equivalent list of names in the other languages in the
to boxes, convert the text in the boxes to arrays, then loop through the
arrays and replace "January" with "Janvier" and "Monday" with "Lundi", etc.

When I run the code below, the first time through the arrays I get the
results I expect, but the remainder of each array never seems to process. I
step through the code and all looks good. If I manually run the Find/Replace
all is OK (February, March, April... are all found and replaced.)

Is there an Excel equivalent to word's Selection.HomeKey wdStory that I need
to invoke, or is there something wrong with my code?

Thanks so much for your help!



Private Sub cmdCancel_Click()
Unload Me
End Sub

Private Sub cmdTrans_Click()

Me.frMonths.Text = Replace(Me.frMonths.Text, Chr(13) & Chr(13), "")

Me.toMonths.Text = Replace(Me.toMonths.Text, vbCrLf, Chr(13))
Me.toMonths.Text = Replace(Me.toMonths.Text, Chr(13), Chr(13))

Me.toMonths.Text = Me.toMonths.Text & Chr(13)

Me.frDays.Text = Replace(Me.frDays.Text, Chr(13) & Chr(13), Chr(13))

Me.toDays.Text = Replace(Me.toDays.Text, vbCrLf, Chr(13))
Me.toDays.Text = Replace(Me.toDays.Text, Chr(13), Chr(13))

Me.toDays.Text = Me.toDays.Text & Chr(13)

Me.Hide

frMonthArray = Split(Me.frMonths.Text, Chr(13))
frDayArray = Split(Me.frDays.Text, Chr(13))

toMonthArray = Split(Me.toMonths.Text, Chr(13))
toDayArray = Split(Me.toDays.Text, Chr(13))

If UBound(frMonthArray) < UBound(toMonthArray) Then
MsgBox "From and to months don't have equal number of elements"
'Exit Sub
End If

If UBound(frDayArray) < UBound(toDayArray) Then
MsgBox "From and to days don't have equal number of elements"
Exit Sub
End If

'THIS WORKS 1st TIME THROUGH, BUT THE REST OF THE ARRAY DOES NOT FIND/REPLACE

For i = 0 To UBound(frMonthArray)
If frMonthArray(i) = "" Or frMonthArray(i) = vbCr Then GoTo
skipmonth
ActiveSheet.Cells.Replace What:=frMonthArray(i),
Replacement:=toMonthArray(i), LookAt:=xlPart, SearchOrder:=xlByRows,
MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
skipmonth:
Next i

For i = 0 To UBound(frDayArray)
Range("A1").Select
If frDayArray(i) = "" Or frDayArray(i) = vbCr Then GoTo skipday
ActiveSheet.Cells.Replace What:=frDayArray(i),
Replacement:=toDayArray(i), LookAt:=xlPart, SearchOrder:=xlByRows,
MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
skipday:
Next i
' Unload Me

End Sub

Private Sub UserForm_Activate()
Dim EngMonthsArr(11)
EngMonthsArr(0) = "January"
EngMonthsArr(1) = "February"
EngMonthsArr(2) = "March"
EngMonthsArr(3) = "April"
EngMonthsArr(4) = "May"
EngMonthsArr(5) = "June"
EngMonthsArr(6) = "July"
EngMonthsArr(7) = "August"
EngMonthsArr(8) = "September"
EngMonthsArr(9) = "October"
EngMonthsArr(10) = "November"
EngMonthsArr(11) = "December"

Dim EngDaysArr(6)
EngDaysArr(0) = "Monday"
EngDaysArr(1) = "Tuesday"
EngDaysArr(2) = "Wednesday"
EngDaysArr(3) = "Thursday"
EngDaysArr(4) = "Friday"
EngDaysArr(5) = "Saturday"
EngDaysArr(6) = "Sunday"

For i = UBound(EngMonthsArr) To 0 Step -1
Me.frMonths.Text = EngMonthsArr(i) & Chr(13) & Me.frMonths.Text
Next i

For i = UBound(EngDaysArr) To 0 Step -1
Me.frDays.Text = EngDaysArr(i) & Chr(13) & Me.frDays.Text
Next i

End Sub

--
Steven Lee
Vaporloop Technology Solutions
 
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 Problem Ed B.[_2_] Excel Discussion (Misc queries) 0 August 16th 08 04:33 PM
Find and Replace problem Lolly[_2_] Excel Programming 5 May 29th 06 04:26 AM
Find-Replace problem nastech Excel Discussion (Misc queries) 1 February 12th 06 05:18 AM
Find replace problem [email protected] Excel Discussion (Misc queries) 2 December 8th 05 10:30 PM
Problem with Find and Replace mjhill01 Excel Worksheet Functions 1 August 18th 05 04:12 AM


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