Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default Input Box Cancel function

My input box works great when a user is filling in the info. But I also want
to give them the option to press cancel if they made a mistake & don't want
to proceed. If they press cancel I want Row 4 to be deleted & the macro to
end. How to I do that?


Range("B4") = InputBox("ENTER YOUR NAME - Press 'Enter' when done")
Range("C4") = InputBox("ENTER THE DATE YOU NEED THE FILE BY - Press
'Enter' when done")

Range("B4").Select
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Input Box Cancel function

Dim varTemp As Variant
Dim blnExit As Boolean

varTemp = InputBox("ENTER YOUR NAME - Press 'Enter' when done")
Range("B4") = varTemp
varTemp = InputBox("ENTER THE DATE YOU NEED THE FILE BY - Press 'Enter' when
done")
Range("C4") = varTemp
If Range("B4") = "" And Range("C4") = "" Then Rows(4).Delete: Exit Sub

If this post helps click Yes
---------------
Jacob Skaria


"Munchkin" wrote:

My input box works great when a user is filling in the info. But I also want
to give them the option to press cancel if they made a mistake & don't want
to proceed. If they press cancel I want Row 4 to be deleted & the macro to
end. How to I do that?


Range("B4") = InputBox("ENTER YOUR NAME - Press 'Enter' when done")
Range("C4") = InputBox("ENTER THE DATE YOU NEED THE FILE BY - Press
'Enter' when done")

Range("B4").Select

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Input Box Cancel function

Something like this maybe...

Dim Answer As String
Answer = InputBox("ENTER YOUR NAME")
If Len(Answer) = 0 Then
Rows(4).Delete
Exit Sub
End If
Range("B4").Value = Answer
Answer = InputBox("ENTER THE DATE YOU NEED THE FILE BY")
If Len(Answer) = 0 Then
Rows(4).Delete
Exit Sub
End If
Range("C4") = Answer
Range("B4").Select
'
' Rest of your code goes here
'

NOTE: Test the code out on a copy of your data as you cannot Undo changes
made my macro code (I'm thinking about the Row 4 delete when I say that)

--
Rick (MVP - Excel)


"Munchkin" wrote in message
...
My input box works great when a user is filling in the info. But I also
want
to give them the option to press cancel if they made a mistake & don't
want
to proceed. If they press cancel I want Row 4 to be deleted & the macro
to
end. How to I do that?


Range("B4") = InputBox("ENTER YOUR NAME - Press 'Enter' when done")
Range("C4") = InputBox("ENTER THE DATE YOU NEED THE FILE BY - Press
'Enter' when done")

Range("B4").Select


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Input Box Cancel function

Another approach which includes a test for valid date entry

Dim Question As Variant
Dim mysheet As Worksheet

Set mysheet = ThisWorkbook.Worksheets("Sheet1") '<< change as required

Question = InputBox("ENTER YOUR NAME - Press 'Enter' when done")

If Question = "" Then GoTo progend

mysheet.Range("B4") = Question

AddDate:
Question = InputBox("ENTER THE DATE YOU NEED THE FILE BY - Press 'Enter'
when done")

If Question = "" Then

GoTo progend

ElseIf IsDate(Question) = False Then

msg = MsgBox("Please Enter A Valid Date", 16, "Date Error")

GoTo AddDate

Else

mysheet.Range("C4") = Question

End If

progend:

With mysheet

If .Range("$B$4").Value = "" Or _
.Range("$C$4").Value = "" Then .Rows(4).Delete

End With


--
jb


"Munchkin" wrote:

My input box works great when a user is filling in the info. But I also want
to give them the option to press cancel if they made a mistake & don't want
to proceed. If they press cancel I want Row 4 to be deleted & the macro to
end. How to I do that?


Range("B4") = InputBox("ENTER YOUR NAME - Press 'Enter' when done")
Range("C4") = InputBox("ENTER THE DATE YOU NEED THE FILE BY - Press
'Enter' when done")

Range("B4").Select

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 389
Default Input Box Cancel function


Sub InputboxExample()

Dim vResult As Variant
vResult = InputBox("Enter a value")

If StrPtr(vResult) = 0 Then
' Cancel pressed
MsgBox "Cancel"
ElseIf vResult = "" Then
' Zero-length string entered
MsgBox "zls"
Else
' Some entry
MsgBox CStr(vResult)
End If

End Sub

--
Regards,
Tim Zych
http://www.higherdata.com
Workbook Compare - Excel data comparison utility

"Munchkin" wrote in message
...
My input box works great when a user is filling in the info. But I also
want
to give them the option to press cancel if they made a mistake & don't
want
to proceed. If they press cancel I want Row 4 to be deleted & the macro
to
end. How to I do that?


Range("B4") = InputBox("ENTER YOUR NAME - Press 'Enter' when done")
Range("C4") = InputBox("ENTER THE DATE YOU NEED THE FILE BY - Press
'Enter' when done")

Range("B4").Select



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Input Box Vs Cancel Ardy Excel Programming 6 September 6th 07 07:44 AM
Input Box - CANCEL Danny Excel Worksheet Functions 6 December 1st 06 02:15 AM
Input box to cancel sub when Cancel is clicked. PCLIVE Excel Programming 5 September 5th 06 03:19 PM
Input box cancel Little Penny Excel Programming 1 August 25th 06 11:50 PM
cancel input ME @ Home Excel Discussion (Misc queries) 1 February 22nd 06 09:49 AM


All times are GMT +1. The time now is 01:03 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"