我试图找出一种方法来显示在Excel中输入的用于确认的数据。我有两个数组。一个带有单位名称,另一个带有所述单位数量。填充数组时,许多数量将为0。如果数量大于0,我只想显示“单位和数量”。我敢肯定有一种更为雄辩的方法来执行此操作,但这是我的代码,因此远。
Sub DataEntry()
Dim i As Long
Dim entry(0 To 51) As Variant
Dim search As Range
Dim units(0 To 51) As Long
Dim txt As String
Dim Correct As String
Set entry(0) = Range("P1")
'Enter the Unit // set entry = to Prime Key. Break out if finished
For i = 0 To 100
entry(i) = InputBox("Enter Prime Key. Enter 0 if finished.")
If entry(i) = 0 Then Exit For
'How many units? // set Range to number of Units.
units(i) = InputBox("Enter number of unit for prime key " & entry(i))
Next i
Do While i < 51
entry(i) = 0
i = i + 1
Loop
For i = 0 To 51
'Find the Unit and fill the amount of units in the box next to it.
With ActiveSheet.Range("P15:P66")
Set search = Range("P15:P66").Find(What:=entry(i), LookIn:=xlValues)
//Struggling here... Trying to figure out how to input the data
//if they choose prime key 1 and then choose 5 units, P15 is the cell prime key 1 is located Q15 is where I would like the 5 units to go.
End With
Next i
'Display Prime Key and number of Units and Total Price
For i = 0 To 51
If units(i) > 0 Then txt = txt & vbCrLf & entry(i) & units(i)
Next i
Correct = InputBox(txt & vbCrLf & "Is this correct? y/n")
If Correct <> "y" Or Correct <> "Y" Then Call DataEntry
'Ask User to verify they are correct.
'If they are correct, end sub if they are not, zero values and reenter.
End Sub
我对原始代码进行了一些编辑,因为我发现了另一种可能的工作方式,但是我仍在努力之中。