VBA Insert Rows Based on Cells with comma

Stephen_IV

Well-known Member
Joined
Mar 17, 2003
Messages
1,180
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have data that has values seperated by a comma in Range("D:D"). I need a single row for that data. Please see below! Thanks in advance!

Book5
ABCD
1IDNameSchCert
2111Mr XSchool A100
3111Mr XSchool A120, 141, 156
4222Mr YSchool Z98,111
5333Mr ASchool D980
6444Mr TSchool X111,115,116,118,110
7555Mr CSchool C98
Sheet1

I need the data to look like this:

Book5
ABCD
1IDNameSchCert
2111Mr XSchool A100
3111Mr XSchool A120
4111Mr XSchool A141
5111Mr XSchool A156
6222Mr YSchool Z98
7222Mr YSchool Z111
8333Mr ASchool D980
9444Mr TSchool X111
10444Mr TSchool X115
11444Mr TSchool X116
12444Mr TSchool X118
13444Mr TSchool X110
14555Mr CSchool C98
Sheet2
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
On row three, you have spaces in between each number, so they are treated as 3 different values.
However, on rows 4 and 6, you do NOT, so it seems to consider it as one long number (if your values are entered as numbers and not text).

So, you need to either have a space between each value, or have the values enteres as text.
Otherwise, Excel is going to see 98,111 as one number, specifically "ninety-eight thousand one-hundred and eleven" and not "ninety-eight and eleven".

Can you confirm which is it, so we know how to create this code?
 
Upvote 0
On row three, you have spaces in between each number, so they are treated as 3 different values.
However, on rows 4 and 6, you do NOT, so it seems to consider it as one long number (if your values are entered as numbers and not text).

So, you need to either have a space between each value, or have the values enteres as text.
Otherwise, Excel is going to see 98,111 as one number, specifically "ninety-eight thousand one-hundred and eleven" and not "ninety-eight and eleven".

Can you confirm which is it, so we know how to create this code?
Thanks Joe, it is one long number. Sorry about that.
 
Upvote 0
If you look at the formula box for cell D4, it then shows 98111, right? with no comma (as the formula box shows the unformatted values)?
That would make this a lot trickier, as the comma isn't really part of the value.

So, are you then saying that you have a mixture of entries, some with spaces like D3:
120, 141, 156
and some long numbers with no commas, i.e.
98111

It can be very difficult to work with inconsistent data, where you have a mixture of text and numeric entries which do not seem to follow any rules.
If you could standardize them, one way or the other (all numeric entries or all text entries), it would go a long way.

If dealing with long numbers, then is really want you want is the number, split in lengths of 3, going from the right to the left?
 
Upvote 0
Thanks for the response. Yes, you are correct. the format is 100,101,102 no spaces. This is a State file and we don't have any control over the export.
In the case that we have 98,100. It should be 098,100 or 1,9 it should be 001,009 so technically 3 digits.
 
Upvote 0
OK, I am very confused now regarding the how the data actually appears in the file.
Note how the cell is formatted, and what is actually contained in the cells are two different things.
Formatting just changes how it appears on the worksheet, but not the actual value in the cell.
You can see how it actually is stored in the cell by selecting the cell, and viewing what it in the formula box.

How is this file coming over to you? As an Excel file, or some other type of file that you are importing into Excel?
Would it be possible to upload the file to some file sharing site for us to inspect exactly what the data looks like?
If it contains other sensitive data, you can really delete everything other than this column. I think that is all we really need to see.
 
Upvote 0
This is an actual sample:

Book4
ABCD
1EIDNameSchoolEndorsementCodes
2111192
3111123,101
4222271
53333305
6444415
7555542
8666615
9777715
10888892
119999165
12123415
13123513,165
1412361,068,107
15123770
16123813,102
171239265
1812405
19124113,102
Sheet2
 
Upvote 0
That does not help me at all, as that just shows the formatted values in column D.
I need to see the underlying values, which is why I wanted the actual file.
If you are unable to provide that, they answer ALL the following questions.

If you click on cell D3, what does it show you in the formula box (f(x)) at the top?
What about cell D14? What does that show in the formula box?

If you enter the following formulas in any blank cells, what do they return:
=ISNUMBER(C3)
=ISNUMBER(D14)
 
Upvote 0
OK, I opened it up, and it is definitely one single numeric entry in each cell (i.e. 23,101 is really just 23101).

You did not answer my question in how this file is coming over to you.
Is it coming over as an Excel file, or is it some sort of text file that you are importing into Excel (if it is, we can handle part of this issue in the import scripts)?

If it is coming over as an Excel file, where all those are numbers, then it sounds like you want to split the numbers, from right to left, in increments of 3.
 
Upvote 0

Forum statistics

Threads
1,224,889
Messages
6,181,608
Members
453,055
Latest member
cope7895

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top