vba code needed

vino.spider

New Member
Joined
Apr 28, 2011
Messages
15
plz help to solve this problem...
1. In sheet1 ,i have 10 rows and 10 columns of cells with data in it..
2. In a input box if i give 5,5 (5 rows and 5 columns) then it had to select
5 cells row wise and column wise RANDAMLY


thanks in advance....
hope u understand my problem...
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hi vino,

This is a basic macro, without errors handling, but it seems it does the job:
(Introduce rows,columns without spaces e.g
Excel Workbook
ABCDEFGHIJ
112345678910
212345678910
312345678910
412345678910
512345678910
612345678910
712345678910
812345678910
912345678910
1012345678910
11
12Ramdom Range to select
13RowsColumns
1472
7,2
#VALUE!
#VALUE!

Hope this helps.

Regards
 
Upvote 0
hi ,
this line throws me an error
RamdomRow = Application.WorksheetFunction.ISO_Ceiling((HighR - 1) * Rnd() + 1)

could u plz explain ...
thanks..
 
Upvote 0
If you're are using Excel 2007 or below versions, replace "ISO_Ceiling" by Int, the line would be as follow:
Code:
RamdomRow = Application.WorksheetFunction.Int((HighR - 1) * Rnd() + 1)

Regards
 
Upvote 0
Hello

A little late, but here's another way, same setup as César.

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> test()<br>  m = 10<br>  <br>  ans = InputBox("Enter Rows and Columns les than ten, separated by comma.", _<br>  Title:="Selecting desired Range")<br>  <br>  <SPAN style="color:#00007F">If</SPAN> ans = "" <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br>  <br>  r = Split(ans, ",")(0)<br>  c = Split(ans, ",")(1)<br>  <br>  rm = m - <SPAN style="color:#00007F">CInt</SPAN>(r) + 1<br>  cm = m - <SPAN style="color:#00007F">CInt</SPAN>(c) + 1<br>  <br>  rs = Int((rm * Rnd) + 1)<br>  cs = Int((cm * Rnd) + 1)<br>  <br>  Cells(rs, cs).Resize(r, c).Select<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0

Forum statistics

Threads
1,224,502
Messages
6,179,126
Members
452,890
Latest member
Nikhil Ramesh

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top