Hello,
This is my first post here so I hope it will go well.
I have learned to write macro's via the internet which is based on copying and adjusting codes that i find on forums like this and this works perfectly fine. However I am stuck on a certain point right now and can't seem to get it to work.
I want to split one cell into two cells before and after the asterisk.
so for instance abcd123*def456 will become abc123 and def456 in adjacent columns. This works perfectly fine (see my code below).
However, now I want to build an If else function in there.
When there is no asterisk "*" in the cell, then I do not want the macro to split the cell (because later I want to filter on the splitted cells).
So I need a code that does something like: If there is an asterisk in the cell, then do my code, else do nothing. I tried to add the lines below, before the splitvalls function and when I run it do not get an error but the cells are also not splitted anymore.
'If InStr(1, "F2","*", 1) Then
'If (cell.Value) = "*" Then<strike></strike>
Thanks in advance
<strike></strike><strike></strike>
This is my first post here so I hope it will go well.
I have learned to write macro's via the internet which is based on copying and adjusting codes that i find on forums like this and this works perfectly fine. However I am stuck on a certain point right now and can't seem to get it to work.
I want to split one cell into two cells before and after the asterisk.
so for instance abcd123*def456 will become abc123 and def456 in adjacent columns. This works perfectly fine (see my code below).
Rich (BB code):
Sub separate cells()
Dim rngBAs Range Dim rng As Range
Dim SH As Worksheet
Set SH = ActiveSheet
Set rngB = SH.Range("F2:F" &SH.Range("F" & SH.Rows.Count).End(xlUp).Row)
For Each rng In rngB
splitVals = Split(rng.Value,"*")
totalVals = UBound(splitVals)
Range(Cells(rng.Row, rng.Column + 1),Cells(rng.Row, _
rng.Column + 1 + totalVals)).Value= splitVals
'Else
'End If
Next
End Sub
However, now I want to build an If else function in there.
When there is no asterisk "*" in the cell, then I do not want the macro to split the cell (because later I want to filter on the splitted cells).
So I need a code that does something like: If there is an asterisk in the cell, then do my code, else do nothing. I tried to add the lines below, before the splitvalls function and when I run it do not get an error but the cells are also not splitted anymore.
'If InStr(1, "F2","*", 1) Then
'If (cell.Value) = "*" Then
Thanks in advance
<strike></strike><strike></strike>