I wished I was better in VBA because I've been searching how to solve this problem since last friday. I'm hoping you guys can help me out or put me in the right direction.
Basically what I need is to find a way to Text-To-Columns, in a fixed range, but only for cells that contain spaces. I need to do this because the range on which TextToColumns is being executed is being filled up over time. If I don't check if a cell to be split contains a space the TextToColumns function will overwrite some of the cells that have been split before. if you just use TextToColumns cells that don't contain the character where the cell should be split still overwrite the cell next to it.
This didn't seemed so hard at first. I know how to to text-to-columns, and I know how to only execute a block of code when a cell contains a space. However putting 1 and 2 together is harder than it seems.
What I have now is this.
What's the best way to solve this? I thought it was easiest to get the range for each individual cell but it seems I can't get the range for a cell. I can get the column number and the row number of each cell but can't generate a range that can be used for TextToColumns.
I hope I'm being clear enough.
Already thanks for anyone that might have read this!
Basically what I need is to find a way to Text-To-Columns, in a fixed range, but only for cells that contain spaces. I need to do this because the range on which TextToColumns is being executed is being filled up over time. If I don't check if a cell to be split contains a space the TextToColumns function will overwrite some of the cells that have been split before. if you just use TextToColumns cells that don't contain the character where the cell should be split still overwrite the cell next to it.
This didn't seemed so hard at first. I know how to to text-to-columns, and I know how to only execute a block of code when a cell contains a space. However putting 1 and 2 together is harder than it seems.
What I have now is this.
Code:
<code>For Each cell In Worksheets("Sheet1").range("B3:B100").Cells
'First check to see if one cell contains spaces. This seems to work.
Dim checkSpaces As Integer
checkSpaces = InStr(1, cell.Value, " ", vbTextCompare)
'Attempt to split cell by cell but can't because the TextToColumns function belongs to the range object and not to a cell.
If checkSpaces = 0 Then
cell.TextToColumns _
Destination:=range("B3"), _
DataType:=xlDelimited, _
Space:=True, _
Other:=False, _
OtherChar:="-"
Else
End If
Next
</code>
What's the best way to solve this? I thought it was easiest to get the range for each individual cell but it seems I can't get the range for a cell. I can get the column number and the row number of each cell but can't generate a range that can be used for TextToColumns.
I hope I'm being clear enough.
Already thanks for anyone that might have read this!