Hi,
I am new to VBA and hope that someone can help with this:
Issue - I wish to create a random row number which I will use to compare two spread sheets.
1) when I type RandBetween(1, NoRow1) I get
"Runtime error '1004':
Unable to get the RandBetween property of the worksheet function class
(NoRow1 is dimed as a string or a double and is the last row with data present) This is placed in a cell on the sheet - say G7
2) I also wish the random number obtained to be placed in for example - cell B7
Overall-
I have 2 files which I wish to compare
I am comparing the 1st & last row and a random row
The 3 rows are copied from sheet 2 & sheet 3 and placed in sheet 1 for comparison.
All this works however I cant get the VBA correct to create the correct coding for the randomisation of the random row to be selected for copying.
Coding:
Dim NoRows1, Nocolumn1 As String
NoRows1 = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
Nocolumn1 = Cells.Find("*", [A1], , , xlByColumns, xlPrevious).Column
Sheets("Comparator sheet").Select
' Sheets("Comparator sheet").Select
Dim DR As Double
DR = WorksheetFunction.RandBetween(1, NoRow1)
Range("b7").Value = DR
I am new to VBA and hope that someone can help with this:
Issue - I wish to create a random row number which I will use to compare two spread sheets.
1) when I type RandBetween(1, NoRow1) I get
"Runtime error '1004':
Unable to get the RandBetween property of the worksheet function class
(NoRow1 is dimed as a string or a double and is the last row with data present) This is placed in a cell on the sheet - say G7
2) I also wish the random number obtained to be placed in for example - cell B7
Overall-
I have 2 files which I wish to compare
I am comparing the 1st & last row and a random row
The 3 rows are copied from sheet 2 & sheet 3 and placed in sheet 1 for comparison.
All this works however I cant get the VBA correct to create the correct coding for the randomisation of the random row to be selected for copying.
Coding:
Dim NoRows1, Nocolumn1 As String
NoRows1 = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
Nocolumn1 = Cells.Find("*", [A1], , , xlByColumns, xlPrevious).Column
Sheets("Comparator sheet").Select
' Sheets("Comparator sheet").Select
Dim DR As Double
DR = WorksheetFunction.RandBetween(1, NoRow1)
Range("b7").Value = DR