Dear All,
First of all, let me introduce myself, as i am new in this forum. I am 23 and currently working as demand forecasting intern.
i am trying to learn VBA, so I read through some tutorial and now i am working on simple projects. In order to undestrand loop, I want to develop macro that would create list of "n" random numbers ("n" located in A1) in the column A. Than it will check how many times the number "N" (N is located in B1) occurred in the list from the column A.
here is my code:
Sub NameX()
Dim Row, RNB As Integer
For Row = 1 To Cells(1, 1)
Cells(Row, 1).Offset(1, 0) = RNB
RNB = Int((36 - 0 + 1) * Rnd + 0)
If Cells(Row, 1) = Cells(1, 2) Then
Cells(Row, 2).Offset(1, 0) = "TRUE"
Else
Cells(Row, 2).Offset(1, 0) = "False"
End If
Next Row
Range("D2").Value = Application.WorkSheetFunction.CountIf (Range("A2:A" & Cells(1,1) + 1), "TRUE")/Application.WorkSheetFunction.Count (Range("A2:A" & Cells(1,1)+1)
End Sub
Problems:
Build in functions does not working
TRUE is written in the cells where numbers are not matching
FALSE is shown when there is different number from number in B1.
I am just beginner, so there are probably many mistakes, so i want to get rid of any wrong practices.
Thank you for any advice and support.
MartinKo
First of all, let me introduce myself, as i am new in this forum. I am 23 and currently working as demand forecasting intern.
i am trying to learn VBA, so I read through some tutorial and now i am working on simple projects. In order to undestrand loop, I want to develop macro that would create list of "n" random numbers ("n" located in A1) in the column A. Than it will check how many times the number "N" (N is located in B1) occurred in the list from the column A.
here is my code:
Sub NameX()
Dim Row, RNB As Integer
For Row = 1 To Cells(1, 1)
Cells(Row, 1).Offset(1, 0) = RNB
RNB = Int((36 - 0 + 1) * Rnd + 0)
If Cells(Row, 1) = Cells(1, 2) Then
Cells(Row, 2).Offset(1, 0) = "TRUE"
Else
Cells(Row, 2).Offset(1, 0) = "False"
End If
Next Row
Range("D2").Value = Application.WorkSheetFunction.CountIf (Range("A2:A" & Cells(1,1) + 1), "TRUE")/Application.WorkSheetFunction.Count (Range("A2:A" & Cells(1,1)+1)
End Sub
Problems:
Build in functions does not working
TRUE is written in the cells where numbers are not matching
FALSE is shown when there is different number from number in B1.
I am just beginner, so there are probably many mistakes, so i want to get rid of any wrong practices.
Thank you for any advice and support.
MartinKo