私はVBAの完全な新人です。私の質問がばかげているように見えるかもしれませんが、ご容赦ください。
私がやりたいことは、先物価格データを抽出するためのユーザー フォーム インターフェイスを Excel で作成することです。08012、08011 などの名前の先物価格を含む約 100 の異なるスプレッドシートがあります。同じ先物の予測を含む同様のスプレッドシートがあり、それらも同じ方法で名前が付けられています。銘柄記号、日付範囲、予測または実際の価格を入力して、正しいスプレッドシートから目的のシリーズを取得できるようなグラフィカル ユーザー インターフェイスを作成したいと考えています。私の最大の問題は、私が VBA の完全な新人であるため、Excel でその種の問題を解決できるかどうかさえわからないことです。
私はいくつかの文献を読んでいて、2 つのテキスト ボックス (1 つは株式シンボルの外観用、もう 1 つは時間範囲用) とオプション ボックス (予測または実際の価格のどちらを表示するかを決定するため) を備えたユーザー フォーム インターフェイスが必要であることに気付きました。 . しかし、ユーザーが入力したデータをプログラムにさらに渡す方法を本当に理解できないのはそれだけなので、Excelは実際に正しいスプレッドシートから正しい在庫を取得します。
ヒント、同様の問題へのリンクは大歓迎です! 問題の説明が不明確で申し訳ありません。必要な詳細をお尋ねください。これが私のコードです:
Private Sub CommandButton1_Click()
Dim a As String
Dim aa As String
Dim myP As Range
Dim myC As Range
Dim t1 As String
Dim tper() As Variant
Dim tper2() As Variant
Dim tper3() As Variant
Dim t2 As Long
Dim t3 As Long
Dim r As Range
Dim rr As Range
Dim rrr As Range
Dim myMax As Long
Dim FindMax As Long
Dim myMin As Long
Dim FindMin As Long
Dim strPath As String
a = TextBox1.Value
If TextBox1.Value = "" Then
MsgBox ("Ange Serie")
Exit Sub
End If
aa = TextBox4.Value
If TextBox4.Value = "" Then
MsgBox ("Ange Prognosår")
Exit Sub
t1 = TextBox2.Value
If TextBox2.Value = "" Then
MsgBox ("Ange Startdatum")
Exit Sub
End If
t2 = Val(t1)
t1 = TextBox3.Value
If TextBox3.Value = "" Then
MsgBox ("Ange Slutdatum")
Exit Sub
End If
t3 = Val(t1)
If OptionButton1.Value = True Then
'Sheets("utfall").Activate
strPath = "C:\Users\dmyshe\Desktop\Dmytro\Utfall.xls"
Workbooks.Open Filename:=strPath, UpdateLinks:=False
ElseIf OptionButton2.Value = True Then
'Sheets("prognoser").Activate
strPath = "C:\Users\dmyshe\Desktop\Dmytro\Prognoser.xls"
Workbooks.Open Filename:=strPath, UpdateLinks:=False
Else
MsgBox ("Fel")
End If
'Application.AskToUpdateLinks = False
Sheets("" & aa).Activate
tper = Range("A3:A500")
tper2 = Range("CL3:CL500")
tper3 = Range("CL3:CL500")
For i = 1 To UBound(tper, 1)
tper(i, 1) = year(tper(i, 1))
Next i
For i = 1 To UBound(tper, 1)
If tper(i, 1) >= t2 Then
tper2(i, 1) = i
End If
Next i
FindMin = Application.Min(tper2)
For i = 1 To UBound(tper, 1)
If tper(i, 1) <= t3 And tper(i, 1) <> 1899 Then
tper3(i, 1) = i
End If
Next i
FindMax = Application.Max(tper3)
Set r = Rows(2).Find("" & a, , xlValues, xlWhole).EntireColumn
Range("CM1:CM" & r.Rows.Count) = r.Value
Set rr = Range("CM" & (FindMin + 1) & ":CM" & (FindMax + 1))
Set rrr = Range("A" & (FindMin + 2) & ":A" & (FindMax + 2))
ThisWorkbook.Activate
Sheets("Blad3").Activate
Range("A:A").Cells.Clear
Range("B:B").Cells.Clear
Range("A1") = "Datum"
Range("B1") = "" & a
Range("A1").Font.Bold = True
Range("B1").Font.Bold = True
Range("B2:B" & (rr.Rows.Count + 1)) = rr.Value
Range("A2:A" & (rrr.Rows.Count + 1)) = rrr.Value
If OptionButton1.Value = True Then
Workbooks("Utfall").Close False
ElseIf OptionButton2.Value = True Then
Workbooks("Prognoser").Close False
End If
End Sub