Optimize Select Random Cell Value Without Duplicates Code

Apr 6, 2013

I have two worksheets. ws1 contains a large number of dates on column 3. ws3 contains around 20 dates on column 3.

I want to pick two dates randomly in ws1 that does not already exist in ws3.

Here is my working code, but it is really slow to process. How to optimize this code? Also I would like to add a function where if the macro is not able to find two random dates that aren't already in ws3 then exit loop.

VB:
Set ws1 = thisworkbook.sheets(1)
Set ws3 = thisworkbook.sheets(3)

lr = ws2.Cells.Find(What:="*", After:=[A1], SearchDirection:=xlPrevious).Row
Set rvis = ws2.Range("c2:c" & lr).SpecialCells(xlCellTypeVisible)
mynodate = 0

[Code] .....

View 7 Replies


ADVERTISEMENT

Speed-Up/Optimize Recorded Macro Code

Aug 30, 2006

Im setting up a spreadsheet that does engineering calculations. Im using macros to run sizes from a standard schedule. It basically takes the values from one sheet (schedule) to another (calculation), then the result from the calculation sheet (Value only, not the link) is pasted back into the schedule. The macro seems very bulky and im sure that it can be made more efficient with a loop. here is a sample of the code from the macro;

Sheets("Calc sheet").Select
Range("C6").Select
ActiveCell.FormulaR1C1 = "=Schedule!R[1]C"
Range("C7").Select
ActiveCell.FormulaR1C1 = "=Schedule!RC[1]"
Range("C8").Select
ActiveCell.FormulaR1C1 = "=Schedule!R[-1]C[2]"
Range("C9").Select
Sheets("Schedule").Select
Range("G7").Select..................

View 3 Replies View Related

Optimize Slow Conditional Formatting Code

Jan 23, 2008

I am having a little trouble with this code, which runs in my simple but efective ressource overview. It loops through a rather large range and assigns interior colour to the cells based on certain criteria. On my stationary machine (Excel 2003) it takes approximately 15-30 seconds to run the code which is acceptable. On my laptop (Excel 2007) it takes 5+ minutes which is unacceptable. Is there a workaround so as to optimize the speed? Further, when I run this workbook on Excel 2007, even entering an integer in the sheet takes 3-4 seconds, and no code is running! In my first version I used a Change_Event to colour cells on the fly but this was slow and prevented multible cell editing as well as pasting values into the appropriate range.

Public Sub Farvelade()
Dim icolor, Navn As Integer
Dim TargetRow, LastRow, Previous As Long
Dim Target As Range
MsgBox "Det kan tage 15-30 sekunder at opdatere ressourcekalenderen"
Range("A5").Activate
Range("A5"). CurrentRegion.Select
'Set range
ActiveCell.Offset(Selection.Rows.Count, 0).Activate
LastRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row.....................

View 8 Replies View Related

Optimize Slow Code And Avoid Copy To Clipboard?

Oct 7, 2013

this code to minimize it and avoid copy to clipboard.

VB:
Sub SapOutputRun()
Application.EnableEvents = False
Application.ScreenUpdating = False

[Code].....

View 2 Replies View Related

Select Cell At Random

Dec 10, 2007

I have an excel sheet attached that I would like to customise to become a random seat picker. I wanted it to select a random cell representing a seat and highlight that cell in someway (e.g. change the background colour or text colour) and display the data within in in a cell in the middle of the sheet.

I have used formula to achieve the later half of the problem but am unsure how to highlight the cell. my current solution uses f9 to refresh the data. Ideally I would like to attach the behaviour to a command button. I have attached the excell sheet and have highlighted the problems I am having.

View 3 Replies View Related

Random Numbers With No Duplicates

Jan 30, 2010

I want to set up a column of numbers that will be random without any repeating numbers.

Example: If I set up for 1,000 rows, I would like the random numbers to be 1 to 1,000, but the catch would be to have no duplicates in the column.

It has been several years since I worked with Excel and I am sure this can be done with a macro, but I am not sure how to go about it right now.

View 8 Replies View Related

Random Generator With No Duplicates

Apr 18, 2013

In Column A I have a list of 8 team names.

In column AB I have a list of 28 weeks written in date format.

In column B I'd like to chose one week from the 28 weeks listed in AB at random. But B2 - B9 can not have the same date (ie could not have two dates for the 19th of April).

How exactly is that done?

Alternatively - is it possible to have in Column AA the 8 team names. In Column AB the 28 weeks. In Column A a random team picked from column AA and in Column B a random date picked from Column AB. Both column A and Column B can not have duplicates... There's 28 weeks with 8 teams - therefore I only need 8 unique weeks.

View 5 Replies View Related

Random Numbers Without Duplicates

Mar 12, 2008

Is there a way to generate random numbers between 1 and 63 without any duplicates?

View 9 Replies View Related

Unique Random Samples - No Duplicates

Sep 4, 2012

I have data table

A3:D103

Column A are unique serial numbers
Column B, C, D contains test values.

F1= 50 (No Of unique random samples to be pulled - No Duplicates)

The out put range for sample data starts from F3:I3

View 5 Replies View Related

Prevent Duplicates In Random Generations

Oct 3, 2006

How do I keep the same names from coming up on the same column when randomly generated there (I hit f9 and names randomly generate on my sheet)? I'm trying to integrate this fix into =IF(Override!G5>0, Override!G5, Shuffle!A34) formula. That formula is the formula that recieves the randomly generated names into the cells I have chosen. The override is so I can do just that if I dont like the generation of names.

example:

name 1
name 2
name 3
name 1 <---if that happens I want this cell to respond by reshuffling until it equals a name that is not in its column, but just that one cell, not the others.

View 9 Replies View Related

Generate Random Number With No Duplicates Between 1 And 8 In A Column

Mar 21, 2014

I need the easiest way to randomize or generate team numbers in a league. Using COL A assign numbers between 1 & 8 without duplicates. Then repeat 5 more times. This has to be done on the spot and has time constraints as the players will be waiting for their team assignments.

EXAMPLE: I have 48 players which will be assigned to 8 teams of 6. I want to randomize the drawing so the same players don't play on the same teams each week. Also to be able to adjust number of teams determined by how many players are present. either 6 , 8, or 10 teams.

View 10 Replies View Related

How Do You Create A Unique Random Number W/o Duplicates

Feb 5, 2008

I'm needing to generate a unique random value for a database with 3546 cases. The unique random values cannot be duplicates of each other. I tried the =RANDLOTTO function that I learned of in an old post on this board, but that results in "#NAME?" appearing in the first cell. I tried to install the Add-Ins (both the Analysis ToolPak and the Analysis ToolPak - VBA, but nothing seems to happen. Is there another way to generate these numbers?

View 9 Replies View Related

VBA Random Name Select

Dec 12, 2012

I have been thinking about a name selection tool that would automatically pick a few names for internal audit. I can handle the useform launch and other basics but here is what I see happening.

1. The empname! sheet contains a list of all the company employees, with employee number in column A, names in column B and an "X" or blank in column C.

2. The main sheet called auditmaster! contains nothing currently

3. When the code is ran the userform prompts the user to select how many individuals to audit by entering an integer in a textbox.

4. If the user selects 5 for instance, the code will run and will select 5 random employees for internal audit. It does this by first checking column A of the empname! sheet and seeing what the highest and lowest numbers are. This would create the range for the random function.

Next if there is an "X" in column C of empname! sheet, those employees numbers are excluded from the random choice.

Following this the function will select the appropriate number of individuals to audit using random again and place their names/number on the masteraudit! sheet.

The detail should be placed as the following, employee number goes to column F, name to column G. Starting with row 10. The code should also number the results 1 - however many were selected for audit in column E.

View 2 Replies View Related

Random Select.

Sep 14, 2008

I want to random select one of the following,red,yellow,blue,green,orange & white. (as text) in cells A2:A1001.

View 9 Replies View Related

Random Number Select

Feb 5, 2007

I need a macro that will select a random number between 1 and 6. ie select the number of a dice. It needs to input 1 random value into one cell and another random value into another. Like the dice values of a monopoly game.

View 9 Replies View Related

How To Select 50 Random Values From Sheet1

Dec 13, 2013

How to copy and paste 50 values randomly from column A in sheet1 to Column A in sheet2.

View 5 Replies View Related

Random Function On Select Range?

Mar 14, 2014

I would like to use the random function on a range of select numbers. I tried randbetween() but it won't work for me since my range of numbers are not in sequence (e.g. 1,2,4,6,7,8,9,10,21). Using randbetween() might result in numbers not within my range..

View 2 Replies View Related

Select Random Cells In The Selection

Feb 8, 2009

I'm trying to select an x number of random selections within the selection.

Basically, lets say A1:A100 is selected, im going to have a inputbox asking how many to select, you put 10 in the inputbox, and then it randomly chooses 10 from A1:A100 and highlights them

This seems easy enough, i can do the input box and know the random function. just not sure how to set the beginning point and the ending point with Cell locations and then have it highlight those selections... a for loop I'm guessing?

View 9 Replies View Related

Select Random Number From List

Oct 23, 2009

Say I have a list of 100 numbers (in column A). What formula would I use to have Excel list (in column B) 50 random numbers from the list of 100 or column A?

View 6 Replies View Related

Select 30 Random Items From A List

Apr 30, 2014

I've got a list of items (formatted alphanumeric) in column G starting at row 2. I would like a cell formula that would randomly select 30 items from this column and place them in column H starting at row 2. One caveat is that the list must remain static once created. If the Rand()function is used, it recalculates whenever the worksheet is updated so that might be a problem.

Cell formula to do this? A VBA solution would be OK as well.

View 9 Replies View Related

Select 81 Winners At Random From 5000 Entries

Nov 26, 2013

I am looking at ways to select 81 winners at random from a spreadsheet with 5000 + names on it. I have tried assigning each cell with a value between 1 and 81 and then removing the duplicates but i cant seem to get excel to pick 81 unique numbers, instead it will pick no number 1, or two number 70s.

I have managed to get a macro to pick 1 cell at random but cant get it to pick across the whole range of 5000.

View 1 Replies View Related

Select Random Rows And Display On New Sheet

Mar 30, 2009

I need the selected rows to be displayed on a new sheet. The idea being that I have a quiz with hundreds of questions and I only want a random selection to appear when I execute the macro. I plan on hiding the original questions and only displaying the randomly selected ones.

Here is the original code from the previous post.

View 14 Replies View Related

Select Random Row, Split Cells To Different Worksheets

Jul 26, 2009

I am trying to write a macro to:

1. Randomly selects 50 rows from 834 on "worksheet 1". There are only two cells per row.

2. Then, it clears "worksheet 2" and "worksheet 3".

3. From each selected row in "Worksheet 1", it splits the two cells and copies the results into two different worksheets, one column per sheet.

4. The rows in the two new worksheets should be congruent (i.e. same selected order from worksheet 1). Keeping the order the same is important.

This is what I have so far:

--------------------
Sub Macro1()
Dim rng As Range
Dim iRow As Long
With Rows("1:834")
Do
iRow = Fix(Rnd() * 834 + 1)
If rng Is Nothing Then
Set rng = .Rows(iRow)
Else
Set rng = Union(rng, .Rows(iRow))
End If
Loop Until rng.Areas.Count >= 50
End With

rng.Select

Selection.Copy Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)

End Sub
-------------------

View 9 Replies View Related

Select Random Cells From Multiple Sheets And Copy

May 10, 2014

I would like to select say 2 id from sheet1 and 2 names from sheet 2 randomly and copy to sheet3, to cells a and b,have seen various codes but none seem to fit the bill.

View 3 Replies View Related

Random Select One Line Of Data For Each Person In A List

Dec 20, 2012

I would like to know how I can get excel to randomly select one line of data for each of the people listed below (so one for bob, one for jenny, one for Trish etc.). I have been trying a mixture of vlookup and rand but to no avail, below is just a sample list but I would like to try it on a large set of data. I have been able to get a random transaction but not one for each person.

Code:
a1
b
c
d
e
f
g
h
i
j

2

3

4
REF_ID
NAME
DATE
BILL TOTAL

[Code] .....

View 1 Replies View Related

Code To Select Cell At End Of Data

May 24, 2007

I am trying to copy/paste the same data range from many sheets into a summary sheet.

Specifically, I'm attempting to copy (B697:G710) from 100 or so sheets into the summary sheet, one after another

I don't know much about VBA and am using the macro recorder. Unfortunately, when I attempt to paste the data from the next sheet to the summary sheet, it overwrites the info from the prior sheet. I have attempted using the down arrow and Ctrl downarrow but the recorded macro continues to select the same cell in the summary sheet into which it pastes the data.

View 9 Replies View Related

VBA Code To Select Last Cell In Row With Data

Jul 7, 2008

I have a row of formulas that reference other sheets in my workbook (i.e. Cell A4=Sheet2!A1, Cell B4=Sheet2!B1, etc). I need to have VBA find the last cell in that row with data. I tried "End(xlToRight).Column" but it goes all the way to the end because all of the cells have formulas. I need to find the last cell that is empty of data or maybe >0 would work.

View 9 Replies View Related

Code To Search And Select A Cell From An Input Box

Feb 23, 2007

I have a button set to bring up an inputbox. enter serial number.

What I need to do is enter the serial number and then have the macro look through a
single column of values to match it then go to that row.

This seemed so simple I thought I could get it but alas here I sit...

I have tried to search the forum for a similar code but haven't found one that was close enough to make sense to me. I have ut together alot of individual actions, but how to get the value inputed to "search" the column and once found go to that row.

I also need to make sure it accounts for new rows being added in the future. (no set row range)

View 9 Replies View Related

VBA Code To Select Cell Range And Save As Text / XML File

Jul 19, 2013

I am trying to write the code to;

1) change to a different sheet
2) select a specific cell range
3) save that range as a text / xml file with a filename derived from a cell outside the given range

Here is where I have got to so far, but it fails

Private Sub Export_Click()
Sheets("Parsed Data").Select
ThisFile = Range("B1").Value
ActiveWindow.SmallScroll Down:=-15
Range("A1:A41").Copy
SaveAs Filename:=ThisFile, _
FileFormat:=xlTextMSDOS
Application.WindowState = xlMinimized

End Sub

View 2 Replies View Related

Lookup Via Macro Code: Find The Match And Then Select That Cell In VBA

May 24, 2008

I have a large database of equipment on one sheet and an input form on another. For inventory control, when a user scans a number into the input form, the main inventory sheet is updated with the current location. I have it working using functions, but I need to do this in VBA. I am looking to do the following;

User enters 2222 on the input form. The code matches 2222 on the inventory sheet, moves the activecell 10 columns and updates a value in that cell. Cell A2343 is "2222" then Cell K2343 is changed to "WAREHOUSE 4". What is the best way to find the match and then select that cell in VBA?

View 8 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved