R
ryguy7272
I am trying to select cells in a used range and perform a ‘text to column’
change on all cells that fall into this used range. I have about 20
occurrences of this: ‘Relative dose [%]’ with some blanks in the cell right
after this language, and then some, well, basically random variables, after
that. Ideally, I’d like to identify the value in each cell in the used
range, and if the value in the cell is ‘Relative dose [%]’ then perform the
‘text to column’ operation on the next cell below that, and run until Excel
finds a blank cell, and then search again for ‘Relative dose [%]’, and so on
and so forth until Excel reaches the end of the used range. My code is below:
Sub TtoC()
'Dim c As Variant
Dim LastRow As Long
Dim i As Long
ActiveSheet.UsedRange.Rows.Hidden = False
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
For i = LastRow To 2 Step -1
If InStr(1, Cells(i, 1), "Relative dose*", vbTextCompare) Then
cell.Select
Selection.TextToColumns Destination:=Range(c),
DataType:=xlDelimited _
, TextQualifier:=xlDoubleQuote,
ConsecutiveDelimiter:=True, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=True,
Other:=False, FieldInfo _
:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4,
1)), TrailingMinusNumbers:=True
Next
End Sub
It fails on the next line. Can someone tell me what is wrong here?
Thanks,
Ryan---
change on all cells that fall into this used range. I have about 20
occurrences of this: ‘Relative dose [%]’ with some blanks in the cell right
after this language, and then some, well, basically random variables, after
that. Ideally, I’d like to identify the value in each cell in the used
range, and if the value in the cell is ‘Relative dose [%]’ then perform the
‘text to column’ operation on the next cell below that, and run until Excel
finds a blank cell, and then search again for ‘Relative dose [%]’, and so on
and so forth until Excel reaches the end of the used range. My code is below:
Sub TtoC()
'Dim c As Variant
Dim LastRow As Long
Dim i As Long
ActiveSheet.UsedRange.Rows.Hidden = False
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
For i = LastRow To 2 Step -1
If InStr(1, Cells(i, 1), "Relative dose*", vbTextCompare) Then
cell.Select
Selection.TextToColumns Destination:=Range(c),
DataType:=xlDelimited _
, TextQualifier:=xlDoubleQuote,
ConsecutiveDelimiter:=True, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=True,
Other:=False, FieldInfo _
:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4,
1)), TrailingMinusNumbers:=True
Next
End Sub
It fails on the next line. Can someone tell me what is wrong here?
Thanks,
Ryan---