Trying to group a set of data

khyros

New Member
Joined
Aug 7, 2018
Messages
1
Hi guys, I've been lurking around for awhile and getting answers, but I appear to be stuck on something that I can't find a solution for. I'm trying to create some groupings of rows, and I was struggling to do that, so I ended up having to resort to a SendKeys command. That's been working fine for awhile, but I have to hit the macro for each group. I'm now trying to automate it so I can just hit it once and it'll do it all for me. However, from what I can gather trying to mess around with it, the SendKeys commands don't get sent until after the macro has finished running. As such, I'm struggling to find a way to reference where I am for the do loop.

My excel sheet ends up with 3 layers of groups... I have an overall group of a specific category, which is marked by a *, and then each individual function within the category has a row and is labeled with a ranking, and each issue within each function within the category has a row but no ranking. I am attempting to group all of the individual issues within a function together (and then the next layer of grouping groups the functions together into the single category).

So, my initial code was

If ActiveCell.Value = "*" Then
SendKeys "{DOWN}", True
End If
SendKeys "{DOWN}", True
SendKeys "^+{DOWN}", True
SendKeys "+{UP}", True
SendKeys "+%{RIGHT}", True
SendKeys "{ENTER}", True
SendKeys "^{DOWN}", True

And what it does is identifies if it's on the main category (via checking for the *) and if it is, then it goes down a row, if not it stays where it is. From there, it goes down a row, ctrl+shift+down to highlight until the next ranking, shift+up to exclude that ranking, shift+alt+right to open the grouping menu, enter to select group rows, and ctrl+down to get to the next ranking.

I want to stop when I reach two * rows in a row, indicating that there's nothing between the two. I figured that would be accomplished by the following:

Do While i = 1


If ActiveCell.Value = "*" Then
SendKeys "{DOWN}", True
End If

If ActiveCell.Offset(1, 0).Value = "*" Then
Exit Do
End If

SendKeys "{DOWN}", True
SendKeys "^+{DOWN}", True
SendKeys "+{UP}", True
SendKeys "+%{RIGHT}", True
SendKeys "{ENTER}", True
SendKeys "^{DOWN}", True



Loop



It makes logical sense to me, but messing around with it, it seems that the SendKeys doesn't happen until after the macro has "fully executed" or something like that (if I just put a counter = 1000 on it, it'll wait around for awhile, and then scream through grouping everything).

I know SendKeys is an awful way to do this, but since I have various amounts of rows that need to be grouped, I'm not quite sure how else to do it. Either thoughts on how I can get around this shortcoming or thoughts on how to replace SendKeys with some other method of grouping?
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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