Grouping and ungrouping a specified range with excel VBA - vba

i have a range of cells (A60 TO Y70) . I would like to group and ungroup the columns of these cells as they are way too broad and thus complexed to view. Is it possible to ungroup and group a specified range with the use of VBA. There are many more ranges of such thus this function would be really useful for me! Thank you:)

You can simply use the group function:
Range("a60", "y70").Group
or ungroup them:
Range("a60", "y70").Ungroup

Related

VBA: range selection

I would like to ask, if I need to select an entire row, start from the 3rd row as a range in VBA, instead of the below line, any better ways to go about it? Many thanks.
Range("C3:C1048576").Select
Assuming your working with an Excel Worksheet, this line will do it
ActiveWorkbook.Worksheets(1).Rows(3).Select

Excel formula into all cell array

Im trying to fill in a formula in a lot of cells using a VBA. The workbook I'm working with looks like this:
I'm trying to fill in a formula starting in B3. I first tried to define a range and insert formula, but my problem is that the range is never the same. Some data sets I have more columns and others i have more rows.
Is there a way to make a VBA that defines the range as all columns with content in Row1 and all rows with content in A?
The formula that I'm trying to inset is like this: =INDEX(Sheet1!$N:$N;MATCH(Sheet3!$A:$A&Sheet3!B$1;Sheet1!$R:$R;0))
I hope someone can help me with my problem.
you could create a dynamic named range that can be used in VBA
Use the below to define the range
=OFFSET(Sheet1!$B$3,0,0,COUNTA(Sheet1!$A:$A)-1,COUNTA(Sheet1!$1:$1)-1)
Changing Sheet1 to that of your sheetname
Assuming that there areno blank columns or rowsin your data set etc.

VBA - How to find frequencies of "x" and "y" in a list

I have a column of names on one page of an excel workbook, I need to find how often each of these names appears in that column and display it on another sheet. For example, the code needs to count "CS" however many times it appears in this column and display it on a separate sheet, then the same with "Grad" and so on. Any tips?
Thanks a lot
That's the primary use of Pivot tables.
Found the solution with a simple function
=COUNTIF(Individual_Stats!D6:D999,"CS")

Output all cells in a named range in Excel?

I have a named range in Excel (called JourneyReference) that contains data to do with common journeys employees make (travel time, distance, etc). I would like to output all of the cells from this named range on several sheets.
The reason I am looking at doing it this way is because the named range will be updated regularly, and thus I'd like the changes in it to propagate through to all the sheets.
Is this possible in Excel 2007? Or, if there is perhaps a better way of doing this, please let me know. Thanks.

How do I select specific cells in VBA?

Basically I need to select specific cells on an excel sheet in vba. For example the code should be able to select a5, a10, a15. I do not want the cells in between them, just the ones I listed. Is there a specific function that will do this? It seems like .Range could only take start cell and ending cell.
You'd use this: Range("A5,A10,A15").Select
To add additional cells, just use more commas.
Alternately, you can utilize the Union method to join multiple range objects into a single Range object.
Note that it is generally not a good idea to select cells in VBA as nearly everything can be done without selection. This is a frequent mistake made by people new to VBA due to generated macros (Record Macro) recreating what you do rather than the result you want.