• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA drilldown code failing to work

BBKP

New Member
Please find attached an excel file with VBA code on sheet "mtd" which is failing to work. The code in module 1 is supposed to enable drilldown from cell C6 in sheet "mtd" which then updates the pivottable filters in sheet "Details". The macro is activated by a double click.

i can send file to whoever wants to assist as at the moment i am failing to load file

Your kind assistance will be greatly appreciated.
 
If you have issue in file upload then send it to me & i will upload here.

imdkbj at outlook dot com
 
Try to UpLoad Your file or
Try to send to @Deepak 's email-address.
I tried to check Your link, but I didn't like warnings.
 

Attachments

  • BBKP.png
    BBKP.png
    50.3 KB · Views: 0
Check D6-cell formula, 'green' gives same result than [TB-report]!D11...
BBKP.png
... and [C4:G4] week numbers seems to fixed ... no good!
You could link those to [TB-report]!C7:G7
... and for Macro, 'RWeek' have to be a number with Match-formula.
Code:
    ReportCat = Cells(ActiveCell.Row, 1)
    RWeek = Cells(4, ActiveCell.Column)
   
    If ReportCat = "" Then
        ActiveCell.Offset(1, 0).Select
        Exit Sub
    End If
   
    If RWeek = "" Then
        ActiveCell.Offset(1, 0).Select
        Exit Sub
    End If
   
    On Error Resume Next
    x = Application.Match(Int(RWeek), Sheets("raw").Range("BB:BB"), 0)
for test and report
 
Check D6-cell formula, 'green' gives same result than [TB-report]!D11...
View attachment 23771
... and [C4:G4] week numbers seems to fixed ... no good!
You could link those to [TB-report]!C7:G7
... and for Macro, 'RWeek' have to be a number with Match-formula.
Code:
    ReportCat = Cells(ActiveCell.Row, 1)
    RWeek = Cells(4, ActiveCell.Column)
  
    If ReportCat = "" Then
        ActiveCell.Offset(1, 0).Select
        Exit Sub
    End If
  
    If RWeek = "" Then
        ActiveCell.Offset(1, 0).Select
        Exit Sub
    End If
  
    On Error Resume Next
    x = Application.Match(Int(RWeek), Sheets("raw").Range("BB:BB"), 0)
for test and report


Thanks for the kind reply.

I have adjusted the "D6" REF error

I ma new to VBA and would be happy to know what the Code you sent me does in simple terms.

Kindly advise whether "RWeek" should be declared as an "integer" not a "string". I have tried to run your code and its reporting error compiler error.

What does the "Int(RWeek" mean? or what does the on Error component mean.

Many Thanks
 
Okay, I'll try.
1) If You double click cell [D6], then RWeek = Cells(4,ActiveCell.Column) gives You "37; "string".
2) 'On Error Resume Next', if next line gives Error then next line will skip ...
without it, Error will stop running code.
3) 'Match', lookup value should be in same type as lookup range.
'RWeek': raw!BB:BB is weeknumber, so 'RWeek' should be number too.
4) 'Int(RWeek)' changes like from "37" to 37
but, I would like to make some changes to Macro ... ?
Code:
Sub DrillDown()
    Dim ReportCat As String
    Dim RWeek As Integer
    Dim x As Long
'   fixed place
    ReportCat = Range("A6")
'   any cell activated from wanted column
    RWeek = Cells(4, ActiveCell.Column)
    If ReportCat = "" Or RWeek = Empty Then
        Range("C4:G4").Select
        ans = MsgBox("Select from these cells!", vbCritical, "ReSelect from correct range!")
        Exit Sub
    End If
    On Error Resume Next
        x = Application.Match(RWeek, Sheets("raw").Range("BB:BB"), 0)
    If Err.Number <> 0 Then
        ans = MsgBox("Cannot find Week", vbCritical, "Error")
        Exit Sub
    End If
    With Sheets("Detail")
        .Visible = True
        .Select
        With .PivotTables("Detail")
            .PivotFields("Financial Category").ClearAllFilters
            .PivotFields("Financial Category").CurrentPage = ReportCat
            .PivotFields("week").ClearAllFilters
            .PivotFields("week").CurrentPage = RWeek
        End With
    End With
End Sub
... and You would make a button to activate that Macro and
BBKP_Btn.png
of course 'delete' that 'DoubleClick' macro!
It could be easy to delete any formula by clicking ... I would think so.
When did You get that error message?
You can run that macro step by step and then You can see ... why? or where?
 
Thanks for the kind reply. I have added the new code you sent and the Button control. i have noted that if i delete code and try to run the macro i get an error message box which gives me code requirements. if i delete certain parameters there seem to be no effect.

So of the two code which one would you recommend as i am now a bit confused. Will the code i initially sent you also give me message boxes, like your code?

which code is more efficient?

Also on sheet 'mtd' how to i remove the REF error when using just two parameters in the Getpivotdata formula. I want the summary total in 'mtd' to agree with the 'detail' sheet. so i want the Getpivotdata formula to only use Week & Cost of sale parameter not Account segment 2.
 
You should replace my previous 'DrillDown' macro with Your 'DrillDown' marco!
.. or You could test both, but those have to have different names!
Hmm.. I'll send the whole file that You can test it with all modifications so far.
Including 'Financial Category' and 'Account Segment 2' selection .. and 'Category' and "Week' selections. Test the effect, please.

Your code gives less message boxes than mine. Sometimes, it's good to user to know, what is problem or so and after that 'Exit'.

Your 3rd question... Can You show the result that You want to see?
... and how do can do it manually? I can try to find how to do it ... ?

Can You give an email-address to send that file?
1.5M is still too big.
 
You should replace my previous 'DrillDown' macro with Your 'DrillDown' marco!
.. or You could test both, but those have to have different names!
Hmm.. I'll send the whole file that You can test it with all modifications so far.
Including 'Financial Category' and 'Account Segment 2' selection .. and 'Category' and "Week' selections. Test the effect, please.

Your code gives less message boxes than mine. Sometimes, it's good to user to know, what is problem or so and after that 'Exit'.

Your 3rd question... Can You show the result that You want to see?
... and how do can do it manually? I can try to find how to do it ... ?

Can You give an email-address to send that file?
1.5M is still too big.

Thank you for taking time out of your busy work to assist. My email address is batanai80@hotmail.com. My 3rd question was seeking a solution to make the Total appearing on 'MTD' e.g. week "36" & "cost of sales" should agree with the grand total on the detail pivot schedule. Looking forward to your kind assistance.
 
Thanks for the files, will review them and let you know. Thank you very much for teaching me best practise VBA tips. Next time will ask you to help me setup a VBA problem fro scratch not just editing an existing code.

Kind Regards
 
If You're using that file,
please notice that [raw]-sheet has formulas ONLY in 1st row!
I tried to get file size smaller and without formulas, size is 0.5k smaller.
There are still things to modify, anyway I hope that You get some ideas.
 
Back
Top