hotseetotsee
New Member
- Joined
- Dec 20, 2016
- Messages
- 7
I am trying to write a code that recognize words and numbers from the string in the cell and splitting it using commas. I have a code that is not yet completed because I did not know how to proceed from there.
My table is similar to the table below:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]A[/TD]
[TD]B[/TD]
[TD]H[/TD]
[/TR]
[TR]
[TD]ID[/TD]
[TD]Task Desc[/TD]
[TD]Predecessors[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Cook Curry[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Buy Groceries[/TD]
[TD]1FS[/TD]
[/TR]
</tbody>[/TABLE]
As for now, I just want to split the Predecessors to recognize the Task ID (which is 1 in the IFS) and the predecessors type (which is FS in the 1FS).
The code that I came up with looked like below:
If any of you know how to do this, please help. I am new to VBA. Much thanks.
My table is similar to the table below:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]A[/TD]
[TD]B[/TD]
[TD]H[/TD]
[/TR]
[TR]
[TD]ID[/TD]
[TD]Task Desc[/TD]
[TD]Predecessors[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Cook Curry[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Buy Groceries[/TD]
[TD]1FS[/TD]
[/TR]
</tbody>[/TABLE]
As for now, I just want to split the Predecessors to recognize the Task ID (which is 1 in the IFS) and the predecessors type (which is FS in the 1FS).
The code that I came up with looked like below:
Code:
Sub SplitPredecessors()
Dim regEx As New RegExp
Dim strPattern As String
Dim strInput As String
Dim Myrange As Range
Set Myrange = ActiveSheet.Range("$H$6")
For Each c In Myrange
strPattern = "([0-9]+(\.[0-9][0-9]?)?{3})([a-zA-Z]{2})"
'([0-9]+(\.[0-9][0-9]?)?{3})([a-zA-Z]{2}) 0-9 recognize number at max 3 digit long
'a-zA-Z recognize letter at max 2 alphabet long
With regEx
.Global = True
.MultiLine = True
.IgnoreCase = False
.Pattern = strPattern
End With
If strPattern <> "" Then
strInput = c.Value
strReplace = "$1"
Else
strInput = c.Value
strReplace = "$2"
End If
Next
End Sub
If any of you know how to do this, please help. I am new to VBA. Much thanks.