Solved

How can I select random rows in excel for auditing

Posted on 2010-09-15
10
819 Views
Last Modified: 2012-08-13
We need to do some auditing in excel and what we require is 50 random rows to be selected from 900 records.

Is this possible? if so how do we go about this?

Many Thanks
0
Comment
Question by:bs_user
  • 4
  • 3
  • 3
10 Comments
 
LVL 50

Accepted Solution

by:
Ingeborg Hawighorst earned 250 total points
ID: 33680590
Hello bs user,

In Excel 2003 or earlier, enable the Analyis Toolpak. In later versions that is not necessary.

Then use a formula like

=RANDBETWEEN(1,900)

and copy it down 49 times to creat 50 random numbers between 1 and 900

cheers, teylyn
0
 
LVL 50

Expert Comment

by:Ingeborg Hawighorst
ID: 33680600
In case you're not familiar with the Analysis ToolPak: To enable it in Excel 2003 or earlier, click Tools - Add-ins - tick the check box next to Analysis ToolPak

cheers, teylyn
0
 
LVL 18

Assisted Solution

by:Cluskitt
Cluskitt earned 250 total points
ID: 33680603
arrAuditRows[1 to 50]
For i=1 to 50
  arrAudit(i)=Int ((900 - 1 + 1) * Rnd + 1)
Next


This will load arrAudit with 50 random numbers between 1 and 900. It can be made more complex. It can be made to check if the value is repeated. It can even check for the number of exact rows. But this is the basic code.
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

Author Comment

by:bs_user
ID: 33680650
Where would I enter that code Cluskitt, im a bit of a newb when it comes to excel
0
 
LVL 50

Expert Comment

by:Ingeborg Hawighorst
ID: 33680671
bs user,

what is your expected outcome?  I read your question that you wanted a list of 50 random numbers between 1 and 900. Why VBA? Can you explain?

cheers, teylyn
0
 

Author Comment

by:bs_user
ID: 33680687
I want to select 50 random rows which contain data.

Say for example we have 2100 rows of data.  We need to audit 50 rows selected by random, when I tested your code it just created random numbers.

Hope that makes a bit more sense, sorry if my explaination is confusing.

Many Thanks
0
 
LVL 18

Expert Comment

by:Cluskitt
ID: 33680699
This is VBA code. It depends on what you want to do. If all you want is to get 50 values and audit the rows manually, then teylyn's solution is good enough. If you want a more complete solution, you can use VBA to, for example, highlight the selected rows. Or to copy those rows into a new sheet. For example, this will create a copy of 50 rows from sheet1 to sheet2:

Sub AuditRows()
  Dim arrAuditRows[1 to 50] As Integer
  For i=1 To 50
    arrAudit(i)=Int ((900 - 1 + 1) * Rnd + 1)
    For a=1 To i
      If arrAudit(i)=arrAudit(a) Then
        arrAudit(i)=0
      End If
    Next
    If arrAudit(i)=0 Then
      i=i-1
    End If
  Next
  For i=1 to 50
    Sheets(1).Cells(arrAudit(i), 1).EntireRow.Copy
    Sheets(2).Cells(i, 1).EntireRow.Paste
  Next
End Sub

To use this macro, you can access the VBA editor (Alt+F11), create a module (on the left side, in the project explorer, right click->Insert->Module) and paste this code there. Then, in excel, View->Macros->View Macros. Select this macro, chose options and assign a key to the shortcut. You can then use the shortcut to run it at will.
   
   
0
 
LVL 50

Expert Comment

by:Ingeborg Hawighorst
ID: 33680710
What do you mean by "I want to select"?

Select and then what? Just select 50 rows? Or do you want to do something with them? Do you want the rows to be highlighted or change color or "select" them in the context of a macro that does some further manipulation?

You need to be a bit more descriptive with your requirements, please.
0
 
LVL 18

Expert Comment

by:Cluskitt
ID: 33680719
If you don't know how many rows you have, you can add:
Dim arrAuditRows[1 to 50], MaxRow As Integer
MaxRow=Cells.Find(What:="*", After:=[A1], SearchDirection:=xlPrevious).Row

And change:
arrAudit(i)=Int ((900 - 1 + 1) * Rnd + 1)
to
arrAudit(i)=Int ((Maxrow - 1 + 1) * Rnd + 1)

This will find the very last cell that has a value, and read it as the last row.
Also, if you have a header, You have to change the 1's with 2's (or appropriate number for first row).
0
 

Author Closing Comment

by:bs_user
ID: 33912495
Thanks for the info
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question