Columns within selection?

tbro

New Member
Joined
Oct 7, 2012
Messages
10
I'm working on creating a 'smart database' i Excel. Let's view my sheets:

1. 'Main' sheet where Mr Planner does his planning, using data from the two following sheets:
2. 'Clients' sheet. Rows contain Customer ID's. Columns contain all articles from next sheet.
3. 'Articles' sheet. Every article contains a bunch of data!

Right now it's only 15 different data (columns) in the Article sheet, but it might grow.
That's why I've separated the clients from the articles. It gets too messy.

Here's the funny part:
Every client is interested in one, some or every article.

That's why I made the 'Clients' sheet easy to overview.

The columns (articles) are compact (width=5) because only the article number is shown.
For every customer (=row) I simply put an X below the article he/she is interested in.
Curious as I am, I though:
"Maybe it's good beeing able to know the beginning and end of all articles and clients?"

Well, here's how I managed to pull that off:
(I've translated all names into english ones, hopefully I didn't miss anything)

Code:
Public FirstRow_Cu, FirstCol_Cu, LastRow_Cu, LastCol_Cu, Area_Cu As Range
Sub AccessPoints()


    Sheets("Customers").Activate


    ' Find FIRST article number (column)
    ' Associated with the heading "ArticleID"
    Set FirstCol_Cu = Cells.Find("Article ID").Offset(0, 1)
    
    ' Find LAST article number (column)
    With Rows(FirstCol_Cu.Row)
        Set LastCol_Cu = .Cells(.Row, Columns.Count).End(xlToLeft)
    End With
    
    ' Find FIRST customer ID (row)
    Set FirstRow_Cu = Cells.Find("Customer ID").Offset(1, 0)
    
    ' Find LAST customer ID (row)
    With Columns(FirstRow_Cu.Column)
        Set LastRow_Cu = .Cells(Rows.Count, .Column).End(xlUp)
    End With
    
    ' Let's name the entire area!
    ' FROM first row and first article
    ' TO last row and last article
    Set Area_Cu = Range(Cells(1, FirstCol_Cu.Column), _
                    Cells(LastRow_Cu.Row, LastCol_Cu.Column))
    
End Sub

Oh, I thought I might use this 'access point' code in other sheets as well.
That's why I've ended all Public ranges with _Cu as in 'Customer Sheet'. ;)

So, now I want the cool option to show my article info.
The info is hidden in rows 2:4, and by hidden I mean the font color is the same as the background color.
Tada.

Code:
Sub Expand()


    ' Retrieve needed data
    Call AccessPoints
       
    ' Am I placed on an article column?!
    If Intersect(ActiveCell, Area_Cu) Is Nothing Then
        MsgBox ("Please select an article!")
        Exit Sub
    Else
        ' Autofit the active article column
        Selection.Columns.EntireColumn.AutoFit
        ' Change font color to REVEAL THE MAGIC INFO!!
        Range(Cells(1, Selection.Column), _
        Cells(3, Selection.Column)).Font.Color = _
        RGB(0, 0, 0)
    End If
    
End Sub

As soon as I got this sub working, I thought:
- Hey, what if I select a range of articles and want all of those columns to expand?

So, that's my question. How the heck do I do that?!
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

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