• 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.

Randomly pick “n” no. of files from a data

DSP Varma

Member
Can someone help me with a vba code for the following:-

1. Randomly pick “n” no. of files (given in D15:D19 of sheet 4) from sheet 1 and paste in Sheet2.


In the given eg:- the following are the no. of files to be picked


safety_invoice_only - 54

safety_personal_care – 32

safety_electrical_equipment – 1

safety_baby_products - 14
 

Attachments

  • Book2.xlsx
    136.6 KB · Views: 1
DSP Varma
Yes,
as above written
and
as that file works, the code is there too.

Hi Vletm,

The reason codes count is not static. It will vary depending on the data. In the given Data it is G4:G8. It may be sometimes G4:G20 0r G4:G6. Can I have a code for that one. Since pivot is overlapping if there are more reason codes I moved the data side. now can i get the code for G4:G8
upload_2018-11-20_0-14-50.png
 

Attachments

  • Book2.xlsb
    96.8 KB · Views: 1
DSP Varma
Why someone would write as (given in D15:D19 of sheet 4)
if someone won't mean that?

Now, something would move some columns right and so ...
what would be next wish... hmm?

Would it more clear to use at once
that pivot table which would be in same place?
Where do need those rows from 14?
 
DSP Varma
Why someone would write as (given in D15:D19 of sheet 4)
if someone won't mean that?

Now, something would move some columns right and so ...
what would be next wish... hmm?

Would it more clear to use at once
that pivot table which would be in same place?
Where do need those rows from 14?

The problem what I faced was, I recorded a macro for pivot table creation where the application_reason_code count was 5 (range was A3:B9) . I also recorded a macro for copying that pivot and pasting special in range A14:B19. Thereafter I used your code. It worked fine. When the application_reason_code count increased to more than 10 the first pivot table creation range increased to A3:B14. so, my copying and pasting macro did not work.

Can you please help me with the random sample data in sheet 2 on the basis of numbers in D4: D8 (this may vary on the basis of application_reason_code count ). This is same as your previous code but here the range is D4:D8 instead of D15:D19. I tried but could not get it
 

Attachments

  • Book2.xlsb
    95.6 KB · Views: 1
DSP Varma
It's always good to get answers to questions which would help You!
I did four ...
and I got hmm? ...
Hmm? ...
I don't know Your term 'pr...lm' neither Your recordings.

I offer this one:
There can be as many rows in pivot-table as there could be.
BUT, if there are NONE, then there would be a challenge! = do not press [ Do It ]

>> You try to keep that pivot-table in same position (left-top-cell)
>> press [ Do It ]
 

Attachments

  • Book2.xlsb
    105.8 KB · Views: 1
DSP Varma
It's always good to get answers to questions which would help You!
I did four ...
and I got hmm? ...
Hmm? ...
I don't know Your term 'pr...lm' neither Your recordings.

I offer this one:
There can be as many rows in pivot-table as there could be.
BUT, if there are NONE, then there would be a challenge! = do not press [ Do It ]

>> You try to keep that pivot-table in same position (left-top-cell)
>> press [ Do It ]

Thank you very much Vletm. You made my day:):):)
 
Back
Top