Page 1
Page 1
Started By
Message

Excel Question: Formating Like Data To Group Together

Posted on 2/20/18 at 9:20 pm
Posted by athenslife101
Member since Feb 2013
18557 posts
Posted on 2/20/18 at 9:20 pm
Hi, I’m trying to create a macro and I feel like it should be a hell of a lot easier than it is.

My current data set looks aproximtaky like:

A123
A123
B123
C123
C123
D123
X123
Y123
Y123
Z123

Where the letter is the first column. I’d like to automate the format into this (please keep in mind I do want the 123s to line up, stupid formating on phone won’t let me):

A123
123

B123

C123
123

D123

X123

Y123
123

Z123

I am not sure how to do this, especially as I expect the first column to change frequently and I am never sure how often the value in column a will repeat.
This post was edited on 2/20/18 at 9:23 pm
Posted by TigerstuckinMS
Member since Nov 2005
33687 posts
Posted on 2/21/18 at 6:54 am to
Split the data set into discrete elements. First element in column A, second in B, and so on. Text-to-columns should do this nicely. If your dataset is a fixed length for each element, easy peasy. This will let you sort by column A, then B, and so on. However you need to sort out your data.

Then, you write a macro. Set a comparison variable to the value in column A, row 1. Start rolling down the column. Compare the value in each cell as you get to it with the comparison variable. IF the value is equal to the comparison THEN delete the value in the cell. ELSE IF the comparison value is not equal to the value in the cell AND the cell above is blank, THEN set the comparison value to the current cell AND insert a blank row. Repeat until you reach a blank cell and stop.

EDIT: Hell, on second thought, you don't even have to do the macro part. After you break it into elements, put some conditional formatting on the first column so that if a cell is equal to the cell above it, the text color becomes the same as the background color. The data will still be there and you can manipulate it, you just won't see it. You won't get the space between groups, though.

EDIT: On third thought, a PivotTable should let you do what you're wanting to do as well if you'd like a nice automatically formatted report you can print out or pdf. You can group on the first element and set it up so you have groups you can expand or collapse with the first element at the top as a section heading and all of the other data elements listed one per row under that section heading. I'm not going to even try to explain those here, though. You're just going to have to learn by doing there.
This post was edited on 2/21/18 at 7:33 am
Posted by Powerman
Member since Jan 2004
162219 posts
Posted on 2/21/18 at 7:15 am to
I'm not exactly sure what he's asking but it doesn't sound like something that you would need a macro for
Posted by TigerstuckinMS
Member since Nov 2005
33687 posts
Posted on 2/21/18 at 7:25 am to
If he wanted to delete the data and get the spacing, he would. I think I misunderstood, though, and he just wanted to not see the data. That conditional formatting thing should do the trick.
This post was edited on 2/21/18 at 7:31 am
Posted by LSUtigerME
Walker, LA
Member since Oct 2012
3795 posts
Posted on 2/21/18 at 10:18 am to
Does it look approximately like that, or like that?

You say it’s the column, but are they all in same column or not? You want them grouped in same column? Will there ever be more than 2 like elements?

If max only two, and elements are sorted in order (in column A), just use a “= IF(A2=A1,CONCATENATE(“ “,MID(A2,2,10)),A2)”

Basically compare the value below to the value above, if equal, write a number of spaces + the data behind the first letter (I used 10 characters here). If not equal, just write the original data.
Posted by foshizzle
Washington DC metro
Member since Mar 2008
40599 posts
Posted on 2/21/18 at 11:39 am to
I'll assume your data currently has this in column A:

A123
A123
B123
B123
etc.

And what you want is this in columns A and B:

A123 123
A123 123
B123 123
B123 123

This is easy. In cell B1 type this formula: =MID(A1,2,LEN(A1))

... and then copy to the end of the column. You can then sort by column B to bring everything together.
Posted by athenslife101
Member since Feb 2013
18557 posts
Posted on 2/21/18 at 11:49 pm to
Apologies for the confusion and delay. And this does have to be a macro because I’m putting some calculations into some of the columns

Every alpha-numeric is its own column.

So right now the information I have looks like this with | being a new column. :

A|1|2|3
A|5|3|2
B|3|2|3
C|5|4|2
C|3|1|2


The future state, which I do by hand now, looks like this

A|1|2|3
|5|3|2
|5|1| valid |50

B|3|2|3| False| -20

C|5|4|2
|3|1|2
|5|2| Valid| 15

Each item in column 1 will change every day and the number of times column 1 items repeats will change every day. So I need to come up with the formatting for the column one that will allow me to format it without having to go through the full process.

Apologies. Trying to keep it simple as possible

Posted by LSUtigerME
Walker, LA
Member since Oct 2012
3795 posts
Posted on 2/22/18 at 7:46 am to
What’s the 3rd row with valid/false?

Is the data always sorted? Or does the macro need to scan the entire set for repeats? Do you want to overwrite the cells, or will the macro write the new formatted dataset to a new sheet/column?

It should be a fairly simple macro, depending on what you want it to do. Do you want the spaced row, and that extra calculated row in there?
Posted by Swoopin
Member since Jun 2011
22030 posts
Posted on 2/22/18 at 2:32 pm to
With each post you're adding another even more confusing element to your question.

A|1|2|3
quote:

|5|3|2


Is this supposed to be on the same row as the above? If not, why does it no longer have an A on its row?

quote:

|5|1| valid |50


Where is "valid" coming from and what does it mean? Plus I don't see these numbers anywhere in your raw dataset next to eachother. And what is the 50?

This post was edited on 2/22/18 at 2:32 pm
Posted by athenslife101
Member since Feb 2013
18557 posts
Posted on 2/22/18 at 8:50 pm to
Sorry I’m vague. This is an accounting spreadsheet. I need the spreadsheet to know how to add the spaces for the different accounts and I need the spreadsheet to know how many times the account repeats to be included into the calculations.

I did part of this before through doing conditional formulas and VLookups but it always ends up falling apart because sometimes, we will have 3 accounts repeating itself and sometimes there will be 4.

I’m doing a horrible job of explaining this so if you don’t want to answer, I won’t feel bad
Posted by LSUtigerME
Walker, LA
Member since Oct 2012
3795 posts
Posted on 2/22/18 at 11:45 pm to
Do you mind sharing the spreadsheet? If not, I’ll try to help you out.

I’m just still not clear on what you want the macro to “execute”. You can write a macro to identify the “A”, then write/store all the data associated with every “A” in the set. It can write it out however you want. Add calculated numbers, etc., format font, cells, borders, etc. It would then move onto the next “B”.

I’d use a combination of do loops and if statements. I did something very similar for another poster for a time sheet, grouping raw time data into a formatted monthly report by person and day per project number. Macros can be finicky too depending on how they’re written. For example, if sorted and only two, it’d only need to check for repeats to the cell above it. If not sorted or variable repeats, it would need to check the entire set at each occurrence. Also changing rows/columns or moving cells can really screw up a macro, whereas formulas can be dynamic references.
This post was edited on 2/22/18 at 11:47 pm
Posted by TheJacer
Member since Nov 2012
789 posts
Posted on 2/23/18 at 9:20 am to
You definitely need to explain the last row with valid in it...the second row looks like you're trying to remove the alpha character, is that accurate?
first pageprev pagePage 1 of 1Next pagelast page
refresh

Back to top
logoFollow TigerDroppings for LSU Football News
Follow us on Twitter, Facebook and Instagram to get the latest updates on LSU Football and Recruiting.

FacebookTwitterInstagram