Frage

Have macro in Excel that uses application.inputbox to save date in cell. Upon entry of date the properly formated date appears in cell and then the inputbox opens again. It seems stuck in this weird loop. No matter how many times I enter the date it asks again.

Here is this section of code:

Function freshSTART()

redBOX.Cells(1).Value = Application.InputBox(prompt:="Enter todays date: ", Title:="TODAY'S DATE", Type:=1)
redBOX.Cells(2).Value = Application.InputBox(prompt:="Enter customer's name: ", Title:="CUSTOMER NAME", Type:=2)
redBOX.Cells(3).Value = Application.InputBox(prompt:="Enter travel out date: ", Title:="TRAVEL OUT DATE", Type:=1)
redBOX.Cells(4).Value = Application.InputBox(prompt:="Enter travel back date: ", Title:="TRAVEL BACK DATE", Type:=1)
redBOX.Cells(5).Value = Application.InputBox(prompt:="Enter number of technicians: ", Title:="TECHNICIANS", Type:=1)
redBOX.Cells(6).Value = Application.InputBox(prompt:="Enter number of engineers: ", Title:="ENGINEERS", Type:=1)
redBOX.Cells(7).Value = Application.InputBox(prompt:="Enter location: ", Title:="LOCATION", Type:=2)

End Function
War es hilfreich?

Lösung

Neither you are passing a parameter nor are you getting a value returned. In that case, it's not useful to have a function but a Subroutine.

Are you calling this function on Worksheet changed or Cell changed events? Please use Application.EnableEvents = False when triggering functions on above events. You have to turn events off or it will keep repeating itself dragging into an infinite loop.

And then in the change event turn events back on.

References:

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top