- My Forums
- Tiger Rant
- LSU Recruiting
- SEC Rant
- Saints Talk
- Pelicans Talk
- More Sports Board
- Fantasy Sports
- Golf Board
- Soccer Board
- O-T Lounge
- Tech Board
- Home/Garden Board
- Outdoor Board
- Health/Fitness Board
- Movie/TV Board
- Book Board
- Music Board
- Political Talk
- Money Talk
- Fark Board
- Gaming Board
- Travel Board
- Food/Drink Board
- Ticket Exchange
- TD Help Board
Customize My Forums- View All Forums
- Show Left Links
- Topic Sort Options
- Trending Topics
- Recent Topics
- Active Topics
Started By
Message
Excel Question: Formating Like Data To Group Together
Posted on 2/20/18 at 9:20 pm
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.
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 on 2/21/18 at 6:54 am to athenslife101
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.
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 on 2/21/18 at 7:15 am to TigerstuckinMS
I'm not exactly sure what he's asking but it doesn't sound like something that you would need a macro for
Posted on 2/21/18 at 7:25 am to Powerman
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 on 2/21/18 at 10:18 am to athenslife101
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.
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 on 2/21/18 at 11:39 am to athenslife101
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.
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 on 2/21/18 at 11:49 pm to foshizzle
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
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 on 2/22/18 at 7:46 am to athenslife101
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?
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 on 2/22/18 at 2:32 pm to athenslife101
With each post you're adding another even more confusing element to your question.
A|1|2|3
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?
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?
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 on 2/22/18 at 8:50 pm to LSUtigerME
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
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 on 2/22/18 at 11:45 pm to athenslife101
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.
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 on 2/23/18 at 9:20 am to athenslife101
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?
Popular
Back to top
Follow TigerDroppings for LSU Football News