Supportnet / Forum / Tabellenkalkulation
Input box
Frage
Hallo zusammen,
ich habe folgeedes problem: Ich habe ein Macro, in welchem ich 10 Variablen habe, die von dem spaeteren Nutzer dieses macros noch festgelegt werden muessen.
Meine Idee war es, dass ueber eine Inputbox zu regeln. Allerdings sind die Variablen aber als Integer deklariert, und muessen das auch bleiben, weil damit gerechnet werden soll. Und soweit ich das verstadne habe, muss man Variablen, die durch Inputboxen bestimmt werden als Strings deklarieren.
Gibt es eine Moeglichkeit Inputboxen umzuwandeln, oder eine andere benutzerfreundliche Variante diese Variablen ueber ein Macro festzulegen (ich hab irgendwo was von "input dialogen" gelesen, konnte aber nicht rausfinden, was das genau ist, und ob dass in diesem Fall besser waere)
Gruss
Henrike
Antwort 1 von Hajo_Zi
Hallo Henrike,
warum müssen die als String definiert werden. Lasse doch nur Zahlen zu.
VarPrints = Application.InputBox("Anzahl der Ausdrucke", "Drucken", 0, Type:=1)
Gruß Hajo
warum müssen die als String definiert werden. Lasse doch nur Zahlen zu.
VarPrints = Application.InputBox("Anzahl der Ausdrucke", "Drucken", 0, Type:=1)
Gruß Hajo
Antwort 2 von JoeKe
Hallo Henrike,
wo steht das du eine InputBox als String deklarieren musst, bzw. das man mit einem String nicht rechnen kann?
Allerdings würde ich sie als Double deklarieren.
Sub eingabe()
Dim eingabe As Double
eingabe = InputBox("Welcher Wert?")
Range("A2") = eingabe * Range("A1")
End Sub
Mit Application.InputBox kannst du festlegen welche Eingaben zulässig sind. Das ist recht gut in der VBA-Hilfe beschrieben.
Sub eingabe2()
Dim eingabe As Double
eingabe = Application.InputBox("Welcher Wert", Type:=1)
Range("A2") = eingabe * Range("A1")
End Sub
Hier werden z.B. nur Zahlen als Eingabe angenommen.
Gruß
JöKe
wo steht das du eine InputBox als String deklarieren musst, bzw. das man mit einem String nicht rechnen kann?
Allerdings würde ich sie als Double deklarieren.
Sub eingabe()
Dim eingabe As Double
eingabe = InputBox("Welcher Wert?")
Range("A2") = eingabe * Range("A1")
End Sub
Mit Application.InputBox kannst du festlegen welche Eingaben zulässig sind. Das ist recht gut in der VBA-Hilfe beschrieben.
Sub eingabe2()
Dim eingabe As Double
eingabe = Application.InputBox("Welcher Wert", Type:=1)
Range("A2") = eingabe * Range("A1")
End Sub
Hier werden z.B. nur Zahlen als Eingabe angenommen.
Gruß
JöKe
Antwort 3 von Henrike
nachdem ich meine inputboxen eigebaut hatte, lief mein Macro nimmer. Und dann hab ich gegooglet und da war ein Artikel, der was von "Macro crashes, if inputboxes are declared as integer" stand.
und mit strings hat mein Macro ueberhaupt nicht gerechnet.
Aber ihr wisst bestimmt besser;o) wahrscheinlich wahr mein Fehelr dann woanders.
Ich probiers jetzt mal mit euren Tipps, vielen Dank!!!!!
und mit strings hat mein Macro ueberhaupt nicht gerechnet.
Aber ihr wisst bestimmt besser;o) wahrscheinlich wahr mein Fehelr dann woanders.
Ich probiers jetzt mal mit euren Tipps, vielen Dank!!!!!
Antwort 4 von Henrike
Hallo nochmal,
ich hab das mit der ApplicationMethod mal eingebaut, aber es funktioniert immer noch nicht. Sprich das Macro haengt sich auf, bzw. hoert nicht auf zu laufen.
Allerdings kann es einzig und allein an den Inputboxen liegen, wenn ich die naemlich rausnehm und statt dessen direkt die gewuenschten Zahlen eingeb, dann laeufts.
Ich schreib euch mal das Macro mal auf:
lobal FirstMonth As Double
Global FirstYear As Double
Global LastMonth As Double
Global LastYear As Double
Global FirstMonthSub As Double
Global FirstYearSub As Double
Global ActualMonthSub As Double
Global ActualYearSub As Double
Global CountSub As Double
Global Sub1 As String
Global Sub2 As String
Sub aaxray()
Application.ScreenUpdating = False
FirstMonth = Application.InputBox("Month of the earliest actual value examined:", Type:=1)
FirstYear = Application.InputBox("Year of the earliest actual value examined:", Type:=1)
LastMonth = Application.InputBox("Month of the latest actual value examined:", Type:=1)
LastYear = Application.InputBox("Year of the latest actual value examined:", Type:=1)
FirstMonthSub = Application.InputBox("Month of the first submission examined:", Type:=1)
FirstYearSub = Application.InputBox("Year of the first submission examined:", Type:=1)
ActualMonthSub = Application.InputBox("Month of the last submission examined:", Type:=1)
ActualYearSub = Application.InputBox("Year of the last submission examined:", Type:=1)
CountSub = Application.InputBox("Number of all submissions in the excel-table:", Type:=1)
Dim month1 As Double
Dim month2 As Double
Dim year1 As Double
Dim year2 As Double
month1 = Application.InputBox("Month of the first submission of the six evaluated for transversal:", Type:=1)
year1 = Application.InputBox("Year of the first submission of the six evaluated for transversal:", Type:=1)
Sub1 = "Sub" & year1 & "-" & month1
month2 = Application.InputBox("Month of the last submission of the six evaluated for transversal:", Type:=1)
year2 = Application.InputBox("Year of the last submission of the six evaluated for transversal:", Type:=1)
Sub2 = "Sub" & year2 & "-" & month2
´FirstMonth = 7
´FirstYear = 2005
´LastMonth = 6
´LastYear = 2006
´FirstMonthSub = 2
´FirstYearSub = 2005
´ActualMonthSub = 7
´ActualYearSub = 2006
´CountSub = 18
´Sub1 = "Sub2005-02"
´Sub2 = "Sub2005-07"
Call ersterRun
Call VollstaendigSub
Call VollstaendigMonth
Call VollstaendigMonth2
Call VollstaendigMonth3
Call Spalten4
Call zweiterRun
Call VollstaendigSuba
Call VollstaendigSub2a
Call VollstaendigSub3a
Call Spalten3
Call VollstaendigMonth
Call VollstaendigMonth2
Call VollstaendigMonth3
Call Spalten4
Call six
Call samplesheet
Call eliminateSamples
Call pivotVertical
Call pivotTransversal
Call Transversal
Call Vertical
Call Monthly
Call Summary
Call VSummary
Call TSummary
Call total
Call Finish
Call pivotChart
Call Chart
Call Last
Call SkuMix
End Sub
ich hab das mit der ApplicationMethod mal eingebaut, aber es funktioniert immer noch nicht. Sprich das Macro haengt sich auf, bzw. hoert nicht auf zu laufen.
Allerdings kann es einzig und allein an den Inputboxen liegen, wenn ich die naemlich rausnehm und statt dessen direkt die gewuenschten Zahlen eingeb, dann laeufts.
Ich schreib euch mal das Macro mal auf:
lobal FirstMonth As Double
Global FirstYear As Double
Global LastMonth As Double
Global LastYear As Double
Global FirstMonthSub As Double
Global FirstYearSub As Double
Global ActualMonthSub As Double
Global ActualYearSub As Double
Global CountSub As Double
Global Sub1 As String
Global Sub2 As String
Sub aaxray()
Application.ScreenUpdating = False
FirstMonth = Application.InputBox("Month of the earliest actual value examined:", Type:=1)
FirstYear = Application.InputBox("Year of the earliest actual value examined:", Type:=1)
LastMonth = Application.InputBox("Month of the latest actual value examined:", Type:=1)
LastYear = Application.InputBox("Year of the latest actual value examined:", Type:=1)
FirstMonthSub = Application.InputBox("Month of the first submission examined:", Type:=1)
FirstYearSub = Application.InputBox("Year of the first submission examined:", Type:=1)
ActualMonthSub = Application.InputBox("Month of the last submission examined:", Type:=1)
ActualYearSub = Application.InputBox("Year of the last submission examined:", Type:=1)
CountSub = Application.InputBox("Number of all submissions in the excel-table:", Type:=1)
Dim month1 As Double
Dim month2 As Double
Dim year1 As Double
Dim year2 As Double
month1 = Application.InputBox("Month of the first submission of the six evaluated for transversal:", Type:=1)
year1 = Application.InputBox("Year of the first submission of the six evaluated for transversal:", Type:=1)
Sub1 = "Sub" & year1 & "-" & month1
month2 = Application.InputBox("Month of the last submission of the six evaluated for transversal:", Type:=1)
year2 = Application.InputBox("Year of the last submission of the six evaluated for transversal:", Type:=1)
Sub2 = "Sub" & year2 & "-" & month2
´FirstMonth = 7
´FirstYear = 2005
´LastMonth = 6
´LastYear = 2006
´FirstMonthSub = 2
´FirstYearSub = 2005
´ActualMonthSub = 7
´ActualYearSub = 2006
´CountSub = 18
´Sub1 = "Sub2005-02"
´Sub2 = "Sub2005-07"
Call ersterRun
Call VollstaendigSub
Call VollstaendigMonth
Call VollstaendigMonth2
Call VollstaendigMonth3
Call Spalten4
Call zweiterRun
Call VollstaendigSuba
Call VollstaendigSub2a
Call VollstaendigSub3a
Call Spalten3
Call VollstaendigMonth
Call VollstaendigMonth2
Call VollstaendigMonth3
Call Spalten4
Call six
Call samplesheet
Call eliminateSamples
Call pivotVertical
Call pivotTransversal
Call Transversal
Call Vertical
Call Monthly
Call Summary
Call VSummary
Call TSummary
Call total
Call Finish
Call pivotChart
Call Chart
Call Last
Call SkuMix
End Sub
Antwort 5 von Henrike
In der ersten zeile des Macros heisst es natuerlich auch "Global", und nicht "lobal"...
Antwort 6 von Hajo_Zi
Hallo Henrike,
ich kann Dein Problem nich nachvollziehen. Ich habe den Code mal auf den Relevanten Teil reduziert. Falls ich Zahlen eingebe läuft er nur einmal durch.
Global FirstMonth As Double
Global FirstYear As Double
Global LastMonth As Double
Global LastYear As Double
Global FirstMonthSub As Double
Global FirstYearSub As Double
Global ActualMonthSub As Double
Global ActualYearSub As Double
Global CountSub As Double
Global Sub1 As String
Global Sub2 As String
Sub aaxray()
Dim month1 As Double
Dim month2 As Double
Dim year1 As Double
Dim year2 As Double
Application.ScreenUpdating = False
FirstMonth = Application.InputBox("Month of the earliest actual value examined:", Type:=1)
FirstYear = Application.InputBox("Year of the earliest actual value examined:", Type:=1)
LastMonth = Application.InputBox("Month of the latest actual value examined:", Type:=1)
LastYear = Application.InputBox("Year of the latest actual value examined:", Type:=1)
FirstMonthSub = Application.InputBox("Month of the first submission examined:", Type:=1)
FirstYearSub = Application.InputBox("Year of the first submission examined:", Type:=1)
ActualMonthSub = Application.InputBox("Month of the last submission examined:", Type:=1)
ActualYearSub = Application.InputBox("Year of the last submission examined:", Type:=1)
CountSub = Application.InputBox("Number of all submissions in the excel-table:", Type:=1)
month1 = Application.InputBox("Month of the first submission of the six evaluated for transversal:", Type:=1)
year1 = Application.InputBox("Year of the first submission of the six evaluated for transversal:", Type:=1)
Sub1 = "Sub" & year1 & "-" & month1
month2 = Application.InputBox("Month of the last submission of the six evaluated for transversal:", Type:=1)
year2 = Application.InputBox("Year of the last submission of the six evaluated for transversal:", Type:=1)
Sub2 = "Sub" & year2 & "-" & month2
Application.ScreenUpdating = True
End Sub
Gruß Hajo
ich kann Dein Problem nich nachvollziehen. Ich habe den Code mal auf den Relevanten Teil reduziert. Falls ich Zahlen eingebe läuft er nur einmal durch.
Global FirstMonth As Double
Global FirstYear As Double
Global LastMonth As Double
Global LastYear As Double
Global FirstMonthSub As Double
Global FirstYearSub As Double
Global ActualMonthSub As Double
Global ActualYearSub As Double
Global CountSub As Double
Global Sub1 As String
Global Sub2 As String
Sub aaxray()
Dim month1 As Double
Dim month2 As Double
Dim year1 As Double
Dim year2 As Double
Application.ScreenUpdating = False
FirstMonth = Application.InputBox("Month of the earliest actual value examined:", Type:=1)
FirstYear = Application.InputBox("Year of the earliest actual value examined:", Type:=1)
LastMonth = Application.InputBox("Month of the latest actual value examined:", Type:=1)
LastYear = Application.InputBox("Year of the latest actual value examined:", Type:=1)
FirstMonthSub = Application.InputBox("Month of the first submission examined:", Type:=1)
FirstYearSub = Application.InputBox("Year of the first submission examined:", Type:=1)
ActualMonthSub = Application.InputBox("Month of the last submission examined:", Type:=1)
ActualYearSub = Application.InputBox("Year of the last submission examined:", Type:=1)
CountSub = Application.InputBox("Number of all submissions in the excel-table:", Type:=1)
month1 = Application.InputBox("Month of the first submission of the six evaluated for transversal:", Type:=1)
year1 = Application.InputBox("Year of the first submission of the six evaluated for transversal:", Type:=1)
Sub1 = "Sub" & year1 & "-" & month1
month2 = Application.InputBox("Month of the last submission of the six evaluated for transversal:", Type:=1)
year2 = Application.InputBox("Year of the last submission of the six evaluated for transversal:", Type:=1)
Sub2 = "Sub" & year2 & "-" & month2
Application.ScreenUpdating = True
End Sub
Gruß Hajo
Antwort 7 von JoeKe
Hallo Henrike,
Dein Ergebnis soll so aussehen:
Sub1 = "Sub2005-02"
wobei die 2005 und die 02 mittels InputBox abgefragt werden.
Da die InputBox, wenn sie vom Typ 1 ist, nur Zahlen als Eingaben akzeptiert, wird der Wert 02 als 2 interpretiert. Weise der InnputBox den Typ 2 Text zu und es sollte funktionieren.
Gruß
JöKe
Dein Ergebnis soll so aussehen:
Sub1 = "Sub2005-02"
wobei die 2005 und die 02 mittels InputBox abgefragt werden.
Da die InputBox, wenn sie vom Typ 1 ist, nur Zahlen als Eingaben akzeptiert, wird der Wert 02 als 2 interpretiert. Weise der InnputBox den Typ 2 Text zu und es sollte funktionieren.
Gruß
JöKe
Antwort 8 von Henrike
Vielen, vielen, vielen, vielen Dank!!!!!
Es laeuft jetzt, genau so, wie ich es wollt!
Gruss
Henrike
Es laeuft jetzt, genau so, wie ich es wollt!
Gruss
Henrike

