I have an excel file where all the data is dumped into 4 cells. Column A has a header and then 4 start times (which will be the same every time) and column B has a header and then 4 cells each of which will contain a different number of email addresses and other details every day so the VBA has to work no matter the density of the cells in column B.
What I want to achieve is neatly stacked rows of data one for each email address no matter the number of addresses in the cell on a given day. The Data is formatted with the row breaks separated by ; and the column breaks separated by , so
[TABLE="width: 500"]
<tbody>[TR]
[TD]Start Time[/TD]
[TD]Details[/TD]
[/TR]
[TR]
[TD]17/07/2016[/TD]
[TD]Jeffsmith@gmail.com,Jeff Smith,555-4196;BobJones@Gmail.com,Bob Jones,555-3827[/TD]
[/TR]
</tbody>[/TABLE]
needs to become
[TABLE="width: 500"]
<tbody>[TR]
[TD]Start Time[/TD]
[TD]Details[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]17/07/2016[/TD]
[TD]Jeffsmith@gmail.com[/TD]
[TD]Jeff Smith[/TD]
[TD]555-4196[/TD]
[/TR]
[TR]
[TD]17/07/2016[/TD]
[TD]BobJones@gmail.com[/TD]
[TD]Bob Jones[/TD]
[TD]555-3827[/TD]
[/TR]
</tbody>[/TABLE]
and so on for each cell no matter how many meail addresses etc there are in B2 B3 B4 and B5 So far I have tried using inserts with the following code
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; white-space: inherit;">RowNum1 =(Len(Range("B2"))- Len(Replace(Range("B2"),"@","")))
RowNum2 =(Len(Range("B3"))- Len(Replace(Range("B3"),"@","")))
RowNum3 =(Len(Range("B4"))- Len(Replace(Range("B4"),"@","")))
RowNum4 =(Len(Range("B5"))- Len(Replace(Range("B5"),"@","")))
If RowNum1 <>0Then
Rows("3:"&1+ RowNum1).EntireRow.Insert
EndIf
If RowNum2 <>0Then
Rows(3+ RowNum1 &":"&1+ RowNum1 + RowNum2).EntireRow.Insert
EndIf
If RowNum3 <>0Then
Rows(3+ RowNum1 + RowNum2 &":"&2+ RowNum1 + RowNum2 + RowNum3).EntireRow.Insert
EndIf
</code>and that seems to put the correct row breaks into the data (I'm not 100% on this) but I'm stumped when it comes to separating the data and putting it where it needs to be. Any help would be greatly appreciated.
What I want to achieve is neatly stacked rows of data one for each email address no matter the number of addresses in the cell on a given day. The Data is formatted with the row breaks separated by ; and the column breaks separated by , so
[TABLE="width: 500"]
<tbody>[TR]
[TD]Start Time[/TD]
[TD]Details[/TD]
[/TR]
[TR]
[TD]17/07/2016[/TD]
[TD]Jeffsmith@gmail.com,Jeff Smith,555-4196;BobJones@Gmail.com,Bob Jones,555-3827[/TD]
[/TR]
</tbody>[/TABLE]
needs to become
[TABLE="width: 500"]
<tbody>[TR]
[TD]Start Time[/TD]
[TD]Details[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]17/07/2016[/TD]
[TD]Jeffsmith@gmail.com[/TD]
[TD]Jeff Smith[/TD]
[TD]555-4196[/TD]
[/TR]
[TR]
[TD]17/07/2016[/TD]
[TD]BobJones@gmail.com[/TD]
[TD]Bob Jones[/TD]
[TD]555-3827[/TD]
[/TR]
</tbody>[/TABLE]
and so on for each cell no matter how many meail addresses etc there are in B2 B3 B4 and B5 So far I have tried using inserts with the following code
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; white-space: inherit;">RowNum1 =(Len(Range("B2"))- Len(Replace(Range("B2"),"@","")))
RowNum2 =(Len(Range("B3"))- Len(Replace(Range("B3"),"@","")))
RowNum3 =(Len(Range("B4"))- Len(Replace(Range("B4"),"@","")))
RowNum4 =(Len(Range("B5"))- Len(Replace(Range("B5"),"@","")))
If RowNum1 <>0Then
Rows("3:"&1+ RowNum1).EntireRow.Insert
EndIf
If RowNum2 <>0Then
Rows(3+ RowNum1 &":"&1+ RowNum1 + RowNum2).EntireRow.Insert
EndIf
If RowNum3 <>0Then
Rows(3+ RowNum1 + RowNum2 &":"&2+ RowNum1 + RowNum2 + RowNum3).EntireRow.Insert
EndIf
</code>and that seems to put the correct row breaks into the data (I'm not 100% on this) but I'm stumped when it comes to separating the data and putting it where it needs to be. Any help would be greatly appreciated.
Last edited: