vba writing from a userform to a spreadsheet

cswan

New Member
Joined
Dec 7, 2010
Messages
13
Hi

I have a userform and I need to be able to write a value entered into a text box from the userform into the next free cell on column C in my spreadsheet.

thanks :)
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Try like this

Code:
Private Sub CommandButton1_Click()
Range("C" & Rows.Count).End(xlUp).Value = TextBox1.Text
End Sub
 
Upvote 0
Thankyou it does write to the correct cell, but it overwrites the last value in the column rather than inserting it underneath in a new cell.
Any ideas?

thanks
 
Upvote 0
Silly me

Rich (BB code):
Private Sub CommandButton1_Click()
Range("C" & Rows.Count).End(xlUp).Offset(1).Value = TextBox1.Text
End Sub
 
Upvote 0
I also have two option buttons on my userform, is there any chance you know how I would make it so when one is pressed it writes "in" to the next available cell in column F or "out" when the other option button is selected to the same column? Perhaps a command button should be added to write the value once the option button has been selected?

Any help would be greatly appreciated

thanks
 
Upvote 0
Try

Code:
Private Sub OptionButton1_Click()
Range("F" & Rows.Count).End(xlUp).Offset(1).Value = "In"
End Sub

Private Sub OptionButton2_Click()
Range("F" & Rows.Count).End(xlUp).Offset(1).Value = "Out"
End Sub
 
Upvote 0
Thankyou, though if someone pressed in and then changed their mind and pressed out it would record both values in the spreadsheet, whereas I need it to only record it once, so perhaps for it to only take notice of the last one pressed.

I'm not really sure if I have explained that very well though

thanks
 
Upvote 0
Perhaps include the options buttons with the previous code:

Code:
Private Sub CommandButton1_Click()
Range("C" & Rows.Count).End(xlUp).Offset(1).Value = TextBox1.Text
If OptionButton1.Value = True Then
    Range("F" & Rows.Count).End(xlUp).Offset(1).Value = "In"
Else
    Range("F" & Rows.Count).End(xlUp).Offset(1).Value = "Out"
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,126
Messages
6,129,007
Members
449,480
Latest member
yesitisasport

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top