Write a sub that finds the first n prime numbers, where you can choose n, and lists them in column B of Sheet1 of the Primes.xlsm file.
Sub PrimeCountSheet1() Dim i, j, n, p, pn As Integer Dim prime As Integer Dim str As String Dim Count As Integer str = "" n = InputBox("Enter how many Prime Number to Display") If (n > 50) Then MsgBox ("Cannot Compute") Exit Sub End If pn = 0 prime = 1 For i = 2 To 10000 If i = 2 Or i = 3 Then pn = pn + 1 str = str + CStr(i) + "," Else For j = 2 To Sqr(i) If (i Mod j = 0) Then prime = 0 GoTo 200 End If p = i Next 200: If prime = 1 Then pn = pn + 1 str = str + CStr(i) + "," End If prime = 1 End If If (pn = n) Then Exit For End If Next [B1].Offset(Count, 0).Value = str Count = Count + 1 End Sub
The part that isn't working for me is the
Next [B1].Offset(Count, 0).Value = str Count = Count + 1 End Sub
Anyone knows how to correct this?