Hi,
I am very new to excel.
I am trying to split the string between the delimiters
And I want the splitted output to be printed in the another sheet.
I am giving input in sheet named "Split", as
A1 A2 A3 A4
a/b/c 10 10 10
d/e/f 20 20 20
g/h 30 30 30
And I want the output in another sheet named "Result".. The expected output is follows.
A1 A2 A3 A4
a 10 10 10
b 10 10 10
c 10 10 10
d 20 20 20
e 20 20 20
f 20 20 20
g 30 30 30
h 30 30 30
My macro is
Sub SplitCells()
Dim fromCol As String
Dim toCol As String
Dim fromRow As String
Dim toRow As String
Dim inVal As String
Dim outVal As String
Dim slashPos As Integer
' Copy from range A1 to range A5.'
fromCol = "A"
fromRow = "1"
toCol = "A"
toRow = "5"
' Go until no more entries in column A.'
inVal = Range(fromCol + fromRow).Value
While inVal <> ""
' Go until all sub-entries used up.'
While inVal <> ""
Range(fromCol + fromRow).Select
' Extract each subentry.'
slashPos = InStr(1, inVal, "/")
While slashPos <> 0
' and write to output column.'
outVal = Left(inVal, slashPos - 1)
Range(toCol + toRow).Select
Rows(1).EntireRow.Copy
Selection.PasteSpecial
Range(toCol + toRow).Value = outVal
toRow = Mid(Str(Val(toRow) + 1), 2)
' Remove that sub-entry.'
inVal = Mid(inVal, slashPos + 1)
While Left(inVal, 1) = " "
inVal = Mid(inVal, 2)
Wend
slashPos = InStr(1, inVal, "/")
Wend
' Get last sub-entry (or full entry if no slash).'
Range(toCol + toRow).Select
Rows(1).EntireRow.Copy
Selection.PasteSpecial
Range(toCol + toRow).Select
Range(toCol + toRow).Value = inVal
toRow = Mid(Str(Val(toRow) + 1), 2)
inVal = ""
Wend
' Advance to next source row.'
fromRow = Mid(Str(Val(fromRow) + 1), 2)
Range(fromCol + fromRow).Select
inVal = Range(fromCol + fromRow).Value
Wend
End Sub
Please do help me with right modification in the above code to achieve my output....
Thank s lot in advance
I am very new to excel.
I am trying to split the string between the delimiters
And I want the splitted output to be printed in the another sheet.
I am giving input in sheet named "Split", as
A1 A2 A3 A4
a/b/c 10 10 10
d/e/f 20 20 20
g/h 30 30 30
And I want the output in another sheet named "Result".. The expected output is follows.
A1 A2 A3 A4
a 10 10 10
b 10 10 10
c 10 10 10
d 20 20 20
e 20 20 20
f 20 20 20
g 30 30 30
h 30 30 30
My macro is
Sub SplitCells()
Dim fromCol As String
Dim toCol As String
Dim fromRow As String
Dim toRow As String
Dim inVal As String
Dim outVal As String
Dim slashPos As Integer
' Copy from range A1 to range A5.'
fromCol = "A"
fromRow = "1"
toCol = "A"
toRow = "5"
' Go until no more entries in column A.'
inVal = Range(fromCol + fromRow).Value
While inVal <> ""
' Go until all sub-entries used up.'
While inVal <> ""
Range(fromCol + fromRow).Select
' Extract each subentry.'
slashPos = InStr(1, inVal, "/")
While slashPos <> 0
' and write to output column.'
outVal = Left(inVal, slashPos - 1)
Range(toCol + toRow).Select
Rows(1).EntireRow.Copy
Selection.PasteSpecial
Range(toCol + toRow).Value = outVal
toRow = Mid(Str(Val(toRow) + 1), 2)
' Remove that sub-entry.'
inVal = Mid(inVal, slashPos + 1)
While Left(inVal, 1) = " "
inVal = Mid(inVal, 2)
Wend
slashPos = InStr(1, inVal, "/")
Wend
' Get last sub-entry (or full entry if no slash).'
Range(toCol + toRow).Select
Rows(1).EntireRow.Copy
Selection.PasteSpecial
Range(toCol + toRow).Select
Range(toCol + toRow).Value = inVal
toRow = Mid(Str(Val(toRow) + 1), 2)
inVal = ""
Wend
' Advance to next source row.'
fromRow = Mid(Str(Val(fromRow) + 1), 2)
Range(fromCol + fromRow).Select
inVal = Range(fromCol + fromRow).Value
Wend
End Sub
Please do help me with right modification in the above code to achieve my output....
Thank s lot in advance