1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
|
Sub TryIt()
Dim LkFor() As String, Info() As String
LookForEqual LkFor, Info
For mI = LBound(LkFor, 1) To UBound(LkFor, 1)
If LkFor(mI) <> "" Then
FindItReplaceIt LkFor(mI), Info(mI)
End If
Next
End Sub
Sub FindItReplaceIt(LookFor As String, ReplaceWith As String)
Dim NewCell As Range, mData As String, firstAddress As String
Dim NumSt As Long, NumEn As Long
Set NewCell = Cells.Find(What:=LookFor, After:=ActiveCell, LookIn:= _
xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext)
While Not NewCell Is Nothing
mData = NewCell.Text
NumSt = InStr(1, mData, LookFor, vbTextCompare)
While Not IsNumeric(Mid(mData, NumSt, 1))
NumSt = NumSt + 1
Wend
NumEn = NumSt
While IsNumeric(Mid(mData, NumEn, 1)) Or Mid(mData, NumEn, 1) = "."
NumEn = NumEn + 1
Wend
mData = Left(mData, NumSt - 1) & ReplaceWith & Mid(mData, NumEn)
Cells(NewCell.Row, NewCell.Column) = mData
Set NewCell = Cells.FindNext(NewCell)
'if I have come back to column 1 I am at the start
If NewCell.Column = 1 Then Exit Sub
Wend
End Sub
Sub LookForEqual(iData() As String, Info() As String)
Dim mCellStr As String, mI As Long, AllD() As String, cnt As Long, mN As Long
ReDim iData(0)
ReDim Info(0)
mN = 0
mCellStr = ActiveCell
AllD = Split(mCellStr, vbLf)
For mI = LBound(AllD, 1) To UBound(AllD, 1)
If InStr(1, AllD(mI), "=") Then
cnt = UBound(iData, 1)
iData(mN) = BreakB4Eq(AllD(mI))
Info(mN) = BreakEq(AllD(mI))
ReDim Preserve iData(cnt + 1)
ReDim Preserve Info(cnt + 1)
mN = mN + 1
End If
Next
End Sub
Function BreakEq(iInfo As String) As String
Dim hldStr As String
hldStr = Mid$(iInfo, InStr(1, iInfo, "=") + 1)
BreakEq = Trim(Replace(Replace(hldStr, "[", ""), "]", ""))
End Function
Function BreakB4Eq(iInfo As String) As String
Dim hldStr As String
hldStr = Trim(Left$(iInfo, InStr(1, iInfo, "=") - 1))
BreakB4Eq = hldStr
End Function
|