dropkickweasel
Board Regular
- Joined
- Feb 2, 2014
- Messages
- 70
Hopefully someone can help me with a problem I'm having with merged cells and a macro not getting on too well...
On a sheet titled "Data", column A has a list of reference numbers.
These are taken from column C on sheet one.
Using "if(Sheet1!C5 = "","",Sheet1!C5), Cell A5 is populated with the appropriate reference number if one has been typed
into Sheet1, else it is left blank.
Cell A5 is merged to include A5 - A10.
Cell A11 is merged to include A11 - A16.
This second cell draws the reference number from cell C6 on Sheet1.
The reason for the merge is that there are a possible of six different similar pieces of information which can be stored in later columns all referring to the same person (and therefore the same reference number).
There are a maximum possible 32 different reference numbers on Sheet1 (C5:C36), which populate 32 different merged cells in column A of the Data sheet (A5:A196)
References will be filled from the first row downwards, but not all rows will have data in them.
What I would like is for a macro to run on Worksheet_Activate() hiding all rows which do not have a reference in them.
I have tried this by using:
Unfortunately when it runs, it recognises that A5 has a reference number, but A6-A10 don't and so hides those five rows and the relevant data in the later columns.
Is there a way to make VBA recognise that the reference typed in cell C5 of Sheet1 applies to ALL of cells A5-A10 of DataSheet and doesn't hide A6-A10 believing them to be blank?
This project is my first foray into VBA, so please be simple with your explanations, so that I can improve and solve my own problems next time...
Many thanks in advance for any support, advice or code that you may offer :]
On a sheet titled "Data", column A has a list of reference numbers.
These are taken from column C on sheet one.
Using "if(Sheet1!C5 = "","",Sheet1!C5), Cell A5 is populated with the appropriate reference number if one has been typed
into Sheet1, else it is left blank.
Cell A5 is merged to include A5 - A10.
Cell A11 is merged to include A11 - A16.
This second cell draws the reference number from cell C6 on Sheet1.
The reason for the merge is that there are a possible of six different similar pieces of information which can be stored in later columns all referring to the same person (and therefore the same reference number).
There are a maximum possible 32 different reference numbers on Sheet1 (C5:C36), which populate 32 different merged cells in column A of the Data sheet (A5:A196)
References will be filled from the first row downwards, but not all rows will have data in them.
What I would like is for a macro to run on Worksheet_Activate() hiding all rows which do not have a reference in them.
I have tried this by using:
Code:
Private Sub Worksheet_Activate()
Application.ScreenUpdating = False
ActiveSheet.Unprotect
For Each Cell In Range("ReferenceNumber")
'ReferenceNumber is the named range A5:A196 on the Data sheet
If Application.WorksheetFunction.IsNumber(Cell) Then
Cell.EntireRow.Hidden = False
Else
Cell.EntireRow.Hidden = True
End If
Next Cell
ActiveSheet.Protect
End Sub
Unfortunately when it runs, it recognises that A5 has a reference number, but A6-A10 don't and so hides those five rows and the relevant data in the later columns.
Is there a way to make VBA recognise that the reference typed in cell C5 of Sheet1 applies to ALL of cells A5-A10 of DataSheet and doesn't hide A6-A10 believing them to be blank?
This project is my first foray into VBA, so please be simple with your explanations, so that I can improve and solve my own problems next time...
Many thanks in advance for any support, advice or code that you may offer :]