Thread: InputBox Help
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\)[_1456_] Rick Rothstein \(MVP - VB\)[_1456_] is offline
external usenet poster
 
Posts: 1
Default InputBox Help

The reason your cell is getting "wiped out" is because you are assigning the
output of the InputBox directly to the ActiveCell (because the Value
property is the default property for a Range). Try it this way...

Sub InputIncTon()
Dim Answer As Variant
Answer = InputBox("What is the INC/TON?", "INC/TON")
If Len(Answer) 0 Then
With Worksheets("Credits")
.Range("G4").Value = Answer
.Range("G4:G600").FillDown
End With
End If
End Sub

Notice that no sheets or cells have to be selected in order to work with
them and that with proper structuring of the If-Then block the GoTo command
was eliminated. Also, my personal preference to check if a text variable is
empty is to see if its length is 0 rather than doing a string comparison to
the empty string ("")... it is faster to do it this way.

Rick


"cottage6" wrote in message
...
Hi All,
I'm sure this is an easy question for most, except for me! I have an
InputBox that gets a value and then copies the number down. Numbers will
already be in the
column from the prior week, and could be used again. However, if the user
invokes the macro by mistake and then clicks "Cancel" the first entry gets
wiped out. I'm pretty sure I could get around this, but I really want the
correct way of doing this. Enclosed is my ratty code; help would be much
appreciated!

Sub InputIncTon()
Sheets("Credits").Select
Range("G4").Select

ActiveCell = InputBox("What is the INC/TON?", "INC/TON")
If ActiveCell = "" Then GoTo GetMeOuttaHere

With Worksheets("Credits")
.Range("G4:G600").FillDown
End With

GetMeOuttaHe

End Sub