Hi all! I'm trying to work with tweets database for the floods in Alberta, Ca in 2013. So I need instead of this:
IDtweet Hashtags Date Other columns
123456789 yycflood#abflood#calgary 01/01/2013
this:
IDtweet Hashtags Date Other columns
123456789 yycflood 01/01/2013
123456789 abflood 01/01/2013
123456789 calgary 01/01/2013
The maximum number of hashtags in cell is 13. So, finally all columns except hashtags should stay the same. I tried this code for cells with number of hashtags from 1 to 3 and just for 2 columns:
Option Explicit
Sub Main()
Columns("F:F").NumberFormat = "@"
Dim i As Long, c As Long, r As Range, v As Variant
For i = 1 To Range("F" & Rows.Count).End(xlUp).Row
v = Split(Range("F" & i), "#")
c = c + UBound(v) + 1
Next i
For i = 2 To c
Set r = Range("F" & i)
Dim arr As Variant
arr = Split(r, "#")
Dim j As Long
r = arr(0)
For j = 1 To UBound(arr)
Rows(r.Row + j & ":" & r.Row + j).Insert Shift:=xlDown
r.Offset(j, 0) = arr(j)
r.Offset(j, -1) = r.Offset(0, -1)
r.Offset(j, 1) = r.Offset(0, 1)
Next j
Next i
For i = 3 To c
Set r = Range("F" & i)
Dim arr As Variant
arr = Split(r, "#")
Dim j As Long
r = arr(0)
For j = 1 To UBound(arr)
Rows(r.Row + j & ":" & r.Row + j).Insert Shift:=xlDown
r.Offset(j, 0) = arr(j)
r.Offset(j, -1) = r.Offset(0, -1)
r.Offset(j, 1) = r.Offset(0, 1)
Next j
Next i
End Sub
But it doesn't work. So, I hope on your help
IDtweet Hashtags Date Other columns
123456789 yycflood#abflood#calgary 01/01/2013
this:
IDtweet Hashtags Date Other columns
123456789 yycflood 01/01/2013
123456789 abflood 01/01/2013
123456789 calgary 01/01/2013
The maximum number of hashtags in cell is 13. So, finally all columns except hashtags should stay the same. I tried this code for cells with number of hashtags from 1 to 3 and just for 2 columns:
Option Explicit
Sub Main()
Columns("F:F").NumberFormat = "@"
Dim i As Long, c As Long, r As Range, v As Variant
For i = 1 To Range("F" & Rows.Count).End(xlUp).Row
v = Split(Range("F" & i), "#")
c = c + UBound(v) + 1
Next i
For i = 2 To c
Set r = Range("F" & i)
Dim arr As Variant
arr = Split(r, "#")
Dim j As Long
r = arr(0)
For j = 1 To UBound(arr)
Rows(r.Row + j & ":" & r.Row + j).Insert Shift:=xlDown
r.Offset(j, 0) = arr(j)
r.Offset(j, -1) = r.Offset(0, -1)
r.Offset(j, 1) = r.Offset(0, 1)
Next j
Next i
For i = 3 To c
Set r = Range("F" & i)
Dim arr As Variant
arr = Split(r, "#")
Dim j As Long
r = arr(0)
For j = 1 To UBound(arr)
Rows(r.Row + j & ":" & r.Row + j).Insert Shift:=xlDown
r.Offset(j, 0) = arr(j)
r.Offset(j, -1) = r.Offset(0, -1)
r.Offset(j, 1) = r.Offset(0, 1)
Next j
Next i
End Sub
But it doesn't work. So, I hope on your help