Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 4th, 2013, 09:02 PM
Registered User
 
Join Date: Jun 2013
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default command inside userform, need help with code

i created a userform with 2 textboxes that stores data in sheet
and then i want the program to loop so that user can add new data t o the sheet i also want the range to change to the next row and add a new row everytime the user adds a new record
right now the code loops and keep on asking to add a new record and the text box only displayes the first time now the add new record program loops all the time why is that and how can it be fixed? thank you very much for your help!!!!!!!!

the following code is inside userform1
Public Sub CommandButton1_Click()



Dim qtest As Integer
Dim qstn As String
qtest = 1
Do While qtest = 1
qtest = 1
Range("a2") = Me.TextBox1.Value
Range("b2") = Me.TextBox2.Value

qstn = InputBox(prompt:="Add more data?")
If qstn = "y" Then
'let program loop to begining of loop and show textbox again
qtest = 1
Else
qtest = 2
Unload UserForm1

End If

Loop
End Sub
 
Old June 5th, 2013, 07:52 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi

You can try something like

Code:
 
 
Do
 
'your statements
 
Range("a2") = Me.TextBox1.Value
Range("b2") = Me.TextBox2.Value
 
Loop Until (MsgBox("Wish To Continue", vbYesNo) = vbNo)
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
 
Old June 5th, 2013, 04:24 PM
Registered User
 
Join Date: Jun 2013
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thank you for being willing to help me i greatly appreciate it!! yes your code is much better!
However the code doesnt work right, it loops without asking me for input
can i
code if vbyesno = vbno
then unload form1
endif /code is the syntax right, yet it doesnt make a difference? what is wrong here?
 
Old June 6th, 2013, 08:22 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi

I had tried the following . Hope it helps

Code:
 
Private Sub CommandButton1_Click()
Do
ActiveSheet.Range("E1").Value = TextBox1.Text
If (MsgBox("Wish to Enter more value", vbYesNo) = vbNo) Then Unload Me
b1 = 1
Loop Until b1 = 1
End Sub
Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
The Following User Says Thank You to Shasur For This Useful Post:
curious2 (June 6th, 2013)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I pass parameter from command line to use inside transform? ilyaz XSLT 1 December 10th, 2010 05:17 PM
Access ASP code inside Javascript deean JSP Basics 1 June 20th, 2008 02:00 PM
Using Custom Code Inside Dataset calexander Reporting Services 0 January 25th, 2007 10:48 AM
Adding code to a button inside a custom Control. Roinka ASP.NET 2.0 Basics 5 April 23rd, 2006 01:03 PM
Code for "Inside COM" dansima Wrox Book Feedback 3 February 17th, 2004 09:09 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.