VBA - input box result to next empty cell

Stephen.Nichols

New Member
Joined
Jul 16, 2008
Messages
40
Hi <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p> </o:p>
I am struggling with my vba code. I need a code that:<o:p></o:p>
<o:p> </o:p>
1. Prompts a user input via an inputbox<o:p></o:p>
2. Place the input box result in the next empty cell in a range<o:p></o:p>

Can anyone help?
 

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"
Hi Stephen, something like this should work:
Code:
Sub nichols()
Dim ans as String, lr as Long
ans = InputBox("Enter some value", "Data Entry Form")
If ans = "" Then
    Exit Sub
Else
    lr = Range("A" & Rows.Count).End(xlUp).Row + 1
    Range("A" & lr).Value = ans
End If
 
Upvote 0
Hello Stephen.Nichols,

This will put the entry into the next empty cell in column "A" of the active sheet.
Code:
  Dim Answer As Variant
  Dim NextCell As Range

    Set NextCell = Cells(Rows.Count, "A").End(xlUp)
    If NextCell.Row > 1 Then NextCell = NextCell.Offset(1, 0)

    Answer = MsgBox("Enter the value.")
    If Answer = "" Then Exit Sub
 
    NextCell = Answer
 
Upvote 0
Thanks for the catch! You are right. I meant InputBox.

Revised Code:
Code:
  Dim Answer As Variant
  Dim NextCell As Range

    Set NextCell = Cells(Rows.Count, "A").End(xlUp)
    If NextCell.Row > 1 Then NextCell = NextCell.Offset(1, 0)

    Answer = InputBox("Enter the value.")
    If Answer = "" Then Exit Sub
 
    NextCell = Answer
 
Upvote 0
Hi,

I've tried to manipulate this to work for me, but I have hit a wall. I need the code to prompt me with an input box when it finds a blank cell in column O. I have a couple problems with the above code: 1) I do not want the code to input the same number for each of the blank cells in column O, but instead prompt me each time a blank cell is found. 2) I need to see the adjacent cells in order to know what to input. Right now it is just showing the top rows, not the blank one.

Thanks for any help!
 
Upvote 0

Forum statistics

Threads
1,221,443
Messages
6,159,907
Members
451,601
Latest member
terrynelson55

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