Hello,
I am not quite sure exactly what you are trying to accomplish. Would you explain a bit further.
Here is what I am working on:
I am currently experimenting with some VBA code to show or hide pictures. I have a pic for each entry in a table list. Depending on the the results of the filter, the corresponding pic will show/hide.
The pics I am using have been renamed like A2 pic, A3 pic ... this gives a reference to the row so the macro can identify which to show/hide.
I am having a little trouble with trapping the filter event (which doesn't exist). One solution is using the calculate event. However, this does not seem to 'fire' after a filter is changed for me. Another solution is using the after calculate event (2007) which shows some promise... I will keep working on it.
I am using the move but don't size property to allow the pics to move up and down depending on the hidden rows.
About how many pics?
What version of Excel? I am using 2007.
What is the table range?
Is renaming the pictures OK?
Here is what I have so far (work in progress):
standard module
Code:
Dim X As New Class1
Sub InitializeApp()
Set X.App = Application
End Sub
class module
Code:
Public WithEvents App As Application
Private Sub App_AfterCalculate()
MsgBox "After Calc"
Dim cell As Range
Dim rngTable As Range
on error resume next
Set rngTable = Range("D2:D4") '''Table range (without header)
For Each cell In rngTable
If cell.EntireRow.Hidden <> True Then
ActiveSheet.Shapes("A" & cell.Row & " pic").Visible = True
Else
ActiveSheet.Shapes("A" & cell.Row & " pic").Visible = False
End If
Next cell
on error goto 0
End Sub
If you would like to test the above, on a
copy:
Alt+F11 to open VBEditor
Keystrokes Alt - I - C to insert a class module.
Paste the above code labeled class module.
Edit the table range to one column of your table
Keystrokes Alt - I - M to insert a standard module.
Paste the above code labeled standard module.
Place your cursor somewhere in the middle of the code.
Press F5
Now close the VBEditor. Each picture will need to be renamed as described above... A4 pic, A500 pic, etc. Lastly, and hopefully, change the filter to see if it works.
-Jeff