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)
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.
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?!
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?!