+ Reply to Thread
Results 1 to 16 of 16

two subs that work seperately, but not together

  1. #1
    Registered User
    Join Date
    12-03-2013
    Location
    perth
    MS-Off Ver
    Excel 2010
    Posts
    9

    two subs that work seperately, but not together

    Hi There. I have two subs which i've got working independently, but when I try and call the alrger sub from the more basic one, i get the error "Argument not optional". I thought at first it was because i was declaring the same variable (Target), but i've changed this so one sub uses Target1 and one just Target, but to no noticeable change. To make it clear what is happening. I have created a data validation list, which a user can select from. This list populates a cell (AP10) and I then am trying to have a pivot table, update based on that cell. AP11 is also a filter I want to apply. I have a large chunk of data that the pivot table points to, with codes for a series of data types, and then data subsets (all 3 character).

    Any help or advice would be greatly appreciated.

    Please Login or Register  to view this content.
    Last edited by Zanthus; 12-01-2014 at 01:27 AM.

  2. #2
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: two subs that work seperately, but not together

    please use code tags for all your coding

    forum rule #3
    http://www.excelforum.com/forum-rule...rum-rules.html

    i see the potential issue but can reply after you have changed your post to use include the code tags
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    Registered User
    Join Date
    12-03-2013
    Location
    perth
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: two subs that work seperately, but not together

    Doneski . I don't do excel code often, and usually i can get things to work, which means I ask questions even less frequently :/

  4. #4
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: two subs that work seperately, but not together

    what i think your missing is the byval in your call code

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    12-03-2013
    Location
    perth
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: two subs that work seperately, but not together

    I had the byval in initially but it didn't work, so removed it. Unfortunately, that doesn't solve the problem.

  6. #6
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: two subs that work seperately, but not together

    you have a 3rd sub filter_pivotfield?
    is that causing the error? or is the error still between worksheet change and update main pivot?

    very hard to determine issue without the file itself
    are you able to attach sample file?
    Last edited by humdingaling; 12-01-2014 at 09:35 PM.

  7. #7
    Registered User
    Join Date
    12-03-2013
    Location
    perth
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: two subs that work seperately, but not together

    I think theres a real chance i'm overcomplicating this. I can't share the actual document because the information is sensitive, but i can eqasily sumarise what it looks like.

    In sheet2, i have a bunch of data. it falls into 12 "areas" identified by a 3 character code (aaa, bbb, ccc etc) - there are 10 possible area codes. Further to this, each of the lines of data has a "type" code of 3 characters - there are 3 possible type codes (abc, abd, abe etc.). Within each of these rows of data, certain cells are populated based on the type. So each area row entry has data in at least 4 columns, but possibly 6, and these columns change (specifically) based on the type.

    What I'm trying to do is copy and paste the matches for each combination. So when a user selects "aaa" and "abc" then copy all rows that match both those criteria, but only columns F,G,H and J. Or if its "aaa" and "abd" then copy each matching row but columns "R,S,T,U,V" etc

    Does this make sense?

    I can probably make a dummy set of data up if that hasnt helped.

    Appreciate the assitance.

  8. #8
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: two subs that work seperately, but not together

    I note that the argument in the declarationg of the Change Event is named Target1. Normally the argument is named Target (no one). This might be causing the problem.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  9. #9
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: two subs that work seperately, but not together

    sorry cant see it
    but it sounds like all you are trying to do is automate pivot table based on DV values

    instead of using DV have you thought about using slicer instead?
    http://www.contextures.com/excelpivottableslicers.html

  10. #10
    Registered User
    Join Date
    12-03-2013
    Location
    perth
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: two subs that work seperately, but not together

    The slicer function acheives the selection of the two selectables, but, it doesnt allow me to dynamically change the column headers and spacing. I've done what im trying to achieve previously and i can re-use that, but it is extraordinarily inelegant and uses 10 x sheet tabs with offset data and just copy-paste code. I'm sure what im looking at can also be done using loops to find values and copy-paste

  11. #11
    Registered User
    Join Date
    12-03-2013
    Location
    perth
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: two subs that work seperately, but not together

    I've found and modified some code that _ALMOST_ does what i want it to, without using pivots. The code below is copying the matched data (correct) to another sheet. The problem is I want to copy more than one cell of data for each matched row, but not the entire row. I can't figure out how to weave that into this code.

    Please Login or Register  to view this content.

  12. #12
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,612

    Re: two subs that work seperately, but not together

    You have: MyArr = Array(Sheets("Sheet6").Range("D4").Value)
    But one cell is not an array and the lower and upper bounds are both zero; your loop iterates only once.
    Then, you are using .Find to locate the value in column F; but, you need some kind of IF condition or lookup table which will tell you which columns to copy based on the found value.
    Ben Van Johnson

  13. #13
    Registered User
    Join Date
    12-03-2013
    Location
    perth
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: two subs that work seperately, but not together

    Yep, I realise that protonLeah, I'm not sure how to create that table in VBA. the number of cells to be copied in each found row, is based on a set criteria. Whilst there are multiple combinations of criteria, there are only 3 identifiers that impact cell copy size.

    Does the actual look of what im messing with help? I've created the dummy data attached.samplesheet1.xlsx

    Sorry if I'm coming accross like a dumbass here :/

  14. #14
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,612

    Re: two subs that work seperately, but not together

    Something like:
    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    12-03-2013
    Location
    perth
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: two subs that work seperately, but not together

    This just copies the cells in the search range, Column F, into the new sheet where they match the contents of D4. I was able to do that without the code addition. I've dummy data running multiple columns over from the range search, so well within the range of the offset parameters.

  16. #16
    Registered User
    Join Date
    12-03-2013
    Location
    perth
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: two subs that work seperately, but not together

    I've just managed to solve it using a nested Index Match as an aray formula! Appreciate your time trying to help though

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Looking to match transactions, in order to work out variances seperately
    By alloygator in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-04-2014, 08:39 AM
  2. [SOLVED] Need help allowing multiple subs to work within one sheet.
    By tknox827 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-13-2012, 12:32 PM
  3. Two Formulas work seperately, but not together.
    By rjhery in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-11-2007, 10:53 AM
  4. copy/paste will work seperately, but not in the function i've writ
    By DP in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-12-2005, 10:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1