OilEconomist
Active Member
- Joined
- Dec 26, 2016
- Messages
- 439
- Office Version
- 2019
- Platform
- Windows
Thanks in advance for your assistance.
I have a MS Excel formula that I would like to convert to VBA. For simplicity I have shortened the code. Yes I know I could just input B2 into the following formula instead of EntryVal1, but as I indicated, I shortened the code so, please understand. What I'm trying to do is extract a value after a character and before another character.
So for example, if B2 is as follows:
Bears vs. Doe, John Foster (SPC: 586982) (DOP: 04/05/1991)
I want C2 to be:
Doe, John Foster
normally, I would just use the following formula into C2, but I am doing something different "=MID(LEFT(A2, FIND(" (SPC: ",A2) -1), FIND("vs. ", A2) + 4, LEN(A2) )"
I am having trouble with the following line
Where my code is as follows
I have a MS Excel formula that I would like to convert to VBA. For simplicity I have shortened the code. Yes I know I could just input B2 into the following formula instead of EntryVal1, but as I indicated, I shortened the code so, please understand. What I'm trying to do is extract a value after a character and before another character.
So for example, if B2 is as follows:
Bears vs. Doe, John Foster (SPC: 586982) (DOP: 04/05/1991)
I want C2 to be:
Doe, John Foster
normally, I would just use the following formula into C2, but I am doing something different "=MID(LEFT(A2, FIND(" (SPC: ",A2) -1), FIND("vs. ", A2) + 4, LEN(A2) )"
I am having trouble with the following line
VBA Code:
EntryVal2 = "=MID(LEFT(" & """ & EntryVal1 & """ & ", FIND("" (SPC: ""," & """ & EntryVal1 & """ & ") -1), FIND(""vs. ""," & """ & EntryVal1 & """ & ") + 4, LEN(" & """ & EntryVal1 & """ & ") )"
Where my code is as follows
VBA Code:
Sub ValGet()
Dim i as Long
Dim EntryVal1 as String
Dim EntryVal2 as String
For i = 2 to 10
EntryVal1 = Range("B" & i).Value
EntryVal2 = "=MID(LEFT(" & """ & EntryVal1 & """ & ", FIND("" (SPC: ""," & """ & EntryVal1 & """ & ") -1), FIND(""vs. ""," & """ & EntryVal1 & """ & ") + 4, LEN(" & """ & EntryVal1 & """ & ") )"
Range("C" & i).Formula = EntryVal2
Range("C" & i).Formula = Range("C" & i).Value
Next i
End Sub