# Problem: Cannot Input Result into Column B of Spreadsheet

Page 1 of 1

## 1 Replies - 831 Views - Last Post: 14 April 2011 - 11:03 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=227523&amp;s=0b30630b36d918ce527e0c9d4c8ee238&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 suspect0908

Reputation: 0
• Posts: 1
• Joined: 13-April 11

# Problem: Cannot Input Result into Column B of Spreadsheet

Posted 13 April 2011 - 02:54 PM

Question:

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.

CODE:

```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?

Is This A Good Question/Topic? 0

## Replies To: Problem: Cannot Input Result into Column B of Spreadsheet

### #2 Ionut

• D.I.C Lover

Reputation: 385
• Posts: 1,057
• Joined: 17-July 10

## Re: Problem: Cannot Input Result into Column B of Spreadsheet

Posted 14 April 2011 - 11:03 PM

```Sheets(1).cells(count,2).value = whatever you want

```