Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Fix InputBox - Returning Empty String

Using inputBox to assign multiple variables and then assigning
the info from those variables to cells which I then reference from
another macro.

What I'm finding is that as already noted here in another thread:

"There is another Inputbox function in VBA which returns an empt
string if cancel is pressed."

This is what seems to be happening if I hit either 'Cancel'
or 'Enter'.

What I'd like to do, is afford the user the opportunity to change
not all or lose all, but to be able to change just some of the
information.

Is there a way with multiple variables to change just some of
the variables but not all without erasing previously entere
information by hitting 'cancel' or 'enter'?

Thanx

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Fix InputBox - Returning Empty String

An input box is generally used for one entry. It is unclear how you are
populating several variables with the results of a single inputbox or how
you would adapt this to allow the user to edit a subset of those entries.

--
Regards,
Tom Ogilvy

"spurtniq" wrote in message
...
Using inputBox to assign multiple variables and then assigning
the info from those variables to cells which I then reference from
another macro.

What I'm finding is that as already noted here in another thread:

"There is another Inputbox function in VBA which returns an empty
string if cancel is pressed."

This is what seems to be happening if I hit either 'Cancel'
or 'Enter'.

What I'd like to do, is afford the user the opportunity to change
not all or lose all, but to be able to change just some of the
information.

Is there a way with multiple variables to change just some of
the variables but not all without erasing previously entered
information by hitting 'cancel' or 'enter'?

Thanx.


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Fix InputBox - Returning Empty String

Here's the (pseudo)code I'm working with:



Sub Create_Header_Cells_Info()

'Left Header Info
sName_1 = InputBox("Data_1", "Data_1", "")
sName_2 = InputBox("Data_2", "Data_2", "")
sName_3 = InputBox("Data_3", "Data_3", "")

'Center Header Info
sName_4 = InputBox("Data_4", "Data_4", "")

'Right Header Info
sName_5 = InputBox("Data_5", "Data_5", "")

Sheets("Sheet1").Range("IV1").Value = sName_1
Sheets("Sheet1").Range("IV2").Value = sName_2
Sheets("Sheet1").Range("IV3").Value = sName_3
Sheets("Sheet1").Range("IV5").Value = sName_4
Sheets("Sheet1").Range("IV7").Value = sName_5
End Sub



Is there a way to modify this as I've suggested or is there
simply a better way to go about it?

hth

Than

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Fix InputBox - Returning Empty String

Hi

In the past, I've achieved this by assigning the current value to a
temporary variable, showing the inputbox and then either re-inserting the
old value (from the temp variable) or inserting the new value. The choice
of which action can be determined by the response from the inputbox - ""
(empty string) indicates "cancel" was clicked....

Hopefully this is of some use

David

"spurtniq" wrote in message
...
Tom Ogilvy wrote:
[b]An input box is generally used for one entry. It is unclear how
you are
populating several variables with the results of a single inputbox or
how
you would adapt this to allow the user to edit a subset of those
entries.

--
Regards,
Tom Ogilvy

You are correct. "InputBox" is generally used for one entry.

I never said I was using "an" inputbox for multiple entries.

I said I was using "inputBox" for several entries. Several
inputBoxes. Several entries using the "inputBox" function.

I, perhaps, could have stated my problem more clearly.

I hope this explanation helps to clarify what I meant.

Now having several entries, I'd like to know how, if it's possible,
by use of the "inputBox" function to NOT have an entry erased
by either hitting the cancel button or Enter key.

Thanx.



---
Message posted from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Fix InputBox - Returning Empty String

David Coleman wrote:
HI

IN THE PAST, I'VE ACHIEVED THIS BY ASSIGNING THE CURRENT VALUE TO A
TEMPORARY VARIABLE, SHOWING THE INPUTBOX AND THEN EITHER RE-INSERTING
THE
OLD VALUE (FROM THE TEMP VARIABLE) OR INSERTING THE NEW VALUE. THE
CHOICE
OF WHICH ACTION CAN BE DETERMINED BY THE RESPONSE FROM THE INPUTBOX -
\"\"
(EMPTY STRING) INDICATES \"CANCEL\" WAS CLICKED....

HOPEFULLY THIS IS OF SOME USE

DAVID




Of Course!

Duh!

(Feeling stupid)

It's only how most applications check for changes.
In this case, a backup copy of the variables...

Thanx for that, David.

Makes perfect sense.


---
Message posted from http://www.ExcelForum.com/



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Fix InputBox - Returning Empty String

Something like this (per David's suggestion)?



Sub Create_Header_Cells_Info()

sName_1_bakup = Sheets("Sheet1").Range("IV1").Value
sName_2_bakup = Sheets("Sheet1").Range("IV1").Value
sName_3_bakup = Sheets("Sheet1").Range("IV1").Value
sName_4_bakup = Sheets("Sheet1").Range("IV1").Value
sName_5_bakup = Sheets("Sheet1").Range("IV1").Value

'Left Header Info
sName_1 = InputBox("Data_1", "Data_1", "")
sName_2 = InputBox("Data_2", "Data_2", "")
sName_3 = InputBox("Data_3", "Data_3", "")

'Center Header Info
sName_4 = InputBox("Data_4", "Data_4", "")

'Right Header Info
sName_5 = InputBox("Data_5", "Data_5", "")

If sName_1 = "" Then
Sheets("Sheet1").Range("IV1").Value = sName_1_bakup
Else
Sheets("Sheet1").Range("IV1").Value = sName_1
End If

If sName_2 = "" Then
Sheets("Sheet1").Range("IV2").Value = sName_2_bakup
Else
Sheets("Sheet1").Range("IV2").Value = sName_2
End If

If sName_3 = "" Then
Sheets("Sheet1").Range("IV3").Value = sName_3_bakup
Else
Sheets("Sheet1").Range("IV3").Value = sName_3
End If

If sName_4 = "" Then
Sheets("Sheet1").Range("IV5").Value = sName_4_bakup
Else
Sheets("Sheet1").Range("IV5").Value = sName_4
End If

If sName_5 = "" Then
Sheets("Sheet1").Range("IV7").Value = sName_5_bakup
Else
Sheets("Sheet1").Range("IV7").Value = sName_5
End If

End Sub




---
Message posted from http://www.ExcelForum.com/

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Fix InputBox - Returning Empty String

Looks like the long way around the block to me. If the user returns "" then
don't update the cell. Why pick up the variable and write back if it never
changes. Did you really mean to pick up all your backup variables from IV1,
then write them to IV1,2,3,5,7?

Seems like you should be using a userform rather than a bunch of input
boxes.

--
Regards,
Tom Ogilvy




"spurtniq" wrote in message
...
Something like this (per David's suggestion)?



Sub Create_Header_Cells_Info()

sName_1_bakup = Sheets("Sheet1").Range("IV1").Value
sName_2_bakup = Sheets("Sheet1").Range("IV1").Value
sName_3_bakup = Sheets("Sheet1").Range("IV1").Value
sName_4_bakup = Sheets("Sheet1").Range("IV1").Value
sName_5_bakup = Sheets("Sheet1").Range("IV1").Value

'Left Header Info
sName_1 = InputBox("Data_1", "Data_1", "")
sName_2 = InputBox("Data_2", "Data_2", "")
sName_3 = InputBox("Data_3", "Data_3", "")

'Center Header Info
sName_4 = InputBox("Data_4", "Data_4", "")

'Right Header Info
sName_5 = InputBox("Data_5", "Data_5", "")

If sName_1 = "" Then
Sheets("Sheet1").Range("IV1").Value = sName_1_bakup
Else
Sheets("Sheet1").Range("IV1").Value = sName_1
End If

If sName_2 = "" Then
Sheets("Sheet1").Range("IV2").Value = sName_2_bakup
Else
Sheets("Sheet1").Range("IV2").Value = sName_2
End If

If sName_3 = "" Then
Sheets("Sheet1").Range("IV3").Value = sName_3_bakup
Else
Sheets("Sheet1").Range("IV3").Value = sName_3
End If

If sName_4 = "" Then
Sheets("Sheet1").Range("IV5").Value = sName_4_bakup
Else
Sheets("Sheet1").Range("IV5").Value = sName_4
End If

If sName_5 = "" Then
Sheets("Sheet1").Range("IV7").Value = sName_5_bakup
Else
Sheets("Sheet1").Range("IV7").Value = sName_5
End If

End Sub




---
Message posted from http://www.ExcelForum.com/



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Fix InputBox - Returning Empty String

Tom Ogilvy wrote:
*Looks like the long way around the block to me. If the user return
"" then
don't update the cell. Why pick up the variable and write back if i
never
changes. Did you really mean to pick up all your backup variable
from IV1,
then write them to IV1,2,3,5,7?

Seems like you should be using a userform rather than a bunch o
input
boxes.
*


The problem I was having was that if I didn't update the cell,
by either "Cancel" or "Enter" then the variable changed to an
empty variable, thereby erasing my original data.

Short of knowing how to not update the variable AND keeping
the previous content in the process, yes, I then mean to pick up
all my backup variables, as David suggested.

I'm new to this.

I haven't figured out userforms yet. They're somewhere down
the list on my long list of things yet to be learned / mastered
regarding Excel.

I'm open to suggestions / examples.

Thanx

--
Message posted from http://www.ExcelForum.com

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
Returning a cell address in a msgbox, by selection via inputbox Ty FARAZ QURESHI Excel Discussion (Misc queries) 3 April 8th 09 12:57 PM
Returning Data to an empty Cell Newfie809 Excel Worksheet Functions 1 August 22nd 08 09:19 PM
Returning an empty cell when no data present Bryan Excel Discussion (Misc queries) 4 November 27th 06 10:51 PM
VBA function returning the value EMPTY Helge V. Larsen[_2_] Excel Programming 1 November 24th 03 12:42 PM
String length of Inputbox user input. Hersh Excel Programming 2 July 14th 03 08:47 PM


All times are GMT +1. The time now is 12:01 AM.

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

About Us

"It's about Microsoft Excel"