PDA

View Full Version : Solved: Define number of cells that should contain data



grizzla
09-19-2008, 03:38 AM
Using vba in Excel 2007

Hi,

I have a userform where the user can define the quantity of a product that is to be made, i already have a worksheet setup that contains the column headings. When the user clicks the OK button i would like the value entered in the quantity textbox to be the number of rows that are populated with numbers 001-the value in Qty.Text.

I have had a search about and cant seem to find anything that would help me do this, if someone knows where i can find an answer please point me in the right direction.

Thankyou

Bob Phillips
09-19-2008, 03:42 AM
Private Sub cmdOK_Click()
Dim i As Long
With Me

If .TextBox1.Text <> "" Then

If IsNumeric(.TextBox1.Text) Then

For i = 1 To Val(TextBox1.Text)

ActiveSheet.Cells(i, "A").Value = i
Next i
End If
End If
End With
End Sub

grizzla
09-22-2008, 02:12 AM
Hi,

thanks for the reply, that does what i need, i was wondering if i can define which cell on the page it starts from. ie A7 on the first page, A46 on the second page and so on.

Thanks again

Bob Phillips
09-22-2008, 02:21 AM
How would you identify the start cell?

grizzla
09-22-2008, 02:28 AM
Basically it needs to start on the seventh row of column A for every page that it is on

Bob Phillips
09-22-2008, 02:32 AM
Private Sub cmdOK_Click()
Dim i As Long
With Me

If .TextBox1.Text <> "" Then

If IsNumeric(.TextBox1.Text) Then

For i = 1 To Val(TextBox1.Text)

ActiveSheet.Cells(i + 6, "A").Value = i
Next i
End If
End If
End With
End Sub

grizzla
09-22-2008, 02:46 AM
Your solution works great, however i best give you some more details (should have done this from the start), page 1 starts from the 7th cell in column A and ends on the 36th cell. I need every page to follow this pattern. If need be i can post my spreadsheet for u to see?

Thanks

Bob Phillips
09-22-2008, 03:38 AM
Seems best.

grizzla
09-22-2008, 03:47 AM
Edited to remove attachment