Arrays 应该是简单的,基于用户输入的带有循环的数组
我需要一个电子表格,提示用户输入以下内容:Arrays 应该是简单的,基于用户输入的带有循环的数组,arrays,vba,loops,user-input,Arrays,Vba,Loops,User Input,我需要一个电子表格,提示用户输入以下内容: Dim i As Integer Dim runTotal As Double Dim resistTotal As Double runTotal = 0 resistTotal = 0 For i = 1 To Range("C2").Value Rows("3").Insert Shift:=xlShiftDown, CopyOrigin:=xlFormatFromRightOrBelow ResistanceValue =
Dim i As Integer
Dim runTotal As Double
Dim resistTotal As Double
runTotal = 0
resistTotal = 0
For i = 1 To Range("C2").Value
Rows("3").Insert Shift:=xlShiftDown, CopyOrigin:=xlFormatFromRightOrBelow
ResistanceValue = InputBox("Hey dude, what is the resistance value in ohms?")
RunLength = InputBox("Cool! How far is it (in feet) from the previous load? Use distance from voltage source if this is the first load.")
ActiveSheet.Range("G3").Value = RunLength
ActiveSheet.Range("D3").Value = ResistanceValue
ActiveSheet.Range("E3").Value = 1 / ResistanceValue
runTotal = runTotal + RunLength
resistTotal = resistTotal + ResistanceValue
If i = Range("C2").Value Then
ActiveSheet.Range("G4").Value = runTotal
ActiveSheet.Range("D4").Value = runTotal
End If
Next i
Dim runArr() As Double
ReDim runArr(1 To QtyEntry)
For i = 1 To Range("C2").Value
'...
runArr(i) = RunLength
Next i
- 他们测试的次数
- 起动电压
- 电路中的电阻器数量
- 电阻之间的距离
- 每个电阻器的电阻
Dim i As Integer
Dim runTotal As Double
Dim resistTotal As Double
runTotal = 0
resistTotal = 0
For i = 1 To Range("C2").Value
Rows("3").Insert Shift:=xlShiftDown, CopyOrigin:=xlFormatFromRightOrBelow
ResistanceValue = InputBox("Hey dude, what is the resistance value in ohms?")
RunLength = InputBox("Cool! How far is it (in feet) from the previous load? Use distance from voltage source if this is the first load.")
ActiveSheet.Range("G3").Value = RunLength
ActiveSheet.Range("D3").Value = ResistanceValue
ActiveSheet.Range("E3").Value = 1 / ResistanceValue
runTotal = runTotal + RunLength
resistTotal = resistTotal + ResistanceValue
If i = Range("C2").Value Then
ActiveSheet.Range("G4").Value = runTotal
ActiveSheet.Range("D4").Value = runTotal
End If
Next i
Dim runArr() As Double
ReDim runArr(1 To QtyEntry)
For i = 1 To Range("C2").Value
'...
runArr(i) = RunLength
Next i
- 等效电阻
- 当前理论
- 每个停止串的电压
- 基于输入值的响应
Private Sub CommandButton21_Click()
TrialRuns = InputBox("How many separate voltage sources have you tested?")
Dim x As Integer
For x = 1 To TrialRuns
TrialName = InputBox("Please input the name or some other type of identifying quality (ie. Level 1 load side)")
Rows("2").Insert Shift:=x1ShiftDown, CopyOrigin:=x1FormatFromRightorBelow
StartingVoltage = "What is the starting voltage?"
Msg = "How many resistors/loads do you have?"
VoltageInput = InputBox(StartingVoltage)
ActiveSheet.Range("A2").Value = TrialName
ActiveSheet.Range("B2").Value = VoltageInput
QtyEntry = InputBox(Msg)
ActiveSheet.Range("C2").Value = QtyEntry
Dim i As Integer
For i = 1 To Range("C2").Value
Rows("3").Insert Shift:=xlShiftDown, CopyOrigin:=xlFormatFromRightOrBelow
ResistanceValue = InputBox("Hey dude, what is the resistance value in ohms?")
RunLength = InputBox("Cool! How far is it (in feet) from the previous load? Use distance from voltage source if this is the first load.")
ActiveSheet.Range("G3").Value = RunLength
ActiveSheet.Range("D3").Value = ResistanceValue
ActiveSheet.Range("E3").Value = 1 / ResistanceValue
Next i
Next x
End Sub
我不完全确定我是否理解您要查找的内容,但您应该能够在不使用数组的情况下获得每个组的总和 在此代码块中添加以下内容:
Dim i As Integer
Dim runTotal As Double
Dim resistTotal As Double
runTotal = 0
resistTotal = 0
For i = 1 To Range("C2").Value
Rows("3").Insert Shift:=xlShiftDown, CopyOrigin:=xlFormatFromRightOrBelow
ResistanceValue = InputBox("Hey dude, what is the resistance value in ohms?")
RunLength = InputBox("Cool! How far is it (in feet) from the previous load? Use distance from voltage source if this is the first load.")
ActiveSheet.Range("G3").Value = RunLength
ActiveSheet.Range("D3").Value = ResistanceValue
ActiveSheet.Range("E3").Value = 1 / ResistanceValue
runTotal = runTotal + RunLength
resistTotal = resistTotal + ResistanceValue
If i = Range("C2").Value Then
ActiveSheet.Range("G4").Value = runTotal
ActiveSheet.Range("D4").Value = runTotal
End If
Next i
Dim runArr() As Double
ReDim runArr(1 To QtyEntry)
For i = 1 To Range("C2").Value
'...
runArr(i) = RunLength
Next i
如果这不能解决您的问题,并且您希望使用阵列,则可以添加类似于以下内容的内容:
Dim i As Integer
Dim runTotal As Double
Dim resistTotal As Double
runTotal = 0
resistTotal = 0
For i = 1 To Range("C2").Value
Rows("3").Insert Shift:=xlShiftDown, CopyOrigin:=xlFormatFromRightOrBelow
ResistanceValue = InputBox("Hey dude, what is the resistance value in ohms?")
RunLength = InputBox("Cool! How far is it (in feet) from the previous load? Use distance from voltage source if this is the first load.")
ActiveSheet.Range("G3").Value = RunLength
ActiveSheet.Range("D3").Value = ResistanceValue
ActiveSheet.Range("E3").Value = 1 / ResistanceValue
runTotal = runTotal + RunLength
resistTotal = resistTotal + ResistanceValue
If i = Range("C2").Value Then
ActiveSheet.Range("G4").Value = runTotal
ActiveSheet.Range("D4").Value = runTotal
End If
Next i
Dim runArr() As Double
ReDim runArr(1 To QtyEntry)
For i = 1 To Range("C2").Value
'...
runArr(i) = RunLength
Next i
我不完全确定我是否理解您要查找的内容,但您应该能够在不使用数组的情况下获得每个组的总和 在此代码块中添加以下内容:
Dim i As Integer
Dim runTotal As Double
Dim resistTotal As Double
runTotal = 0
resistTotal = 0
For i = 1 To Range("C2").Value
Rows("3").Insert Shift:=xlShiftDown, CopyOrigin:=xlFormatFromRightOrBelow
ResistanceValue = InputBox("Hey dude, what is the resistance value in ohms?")
RunLength = InputBox("Cool! How far is it (in feet) from the previous load? Use distance from voltage source if this is the first load.")
ActiveSheet.Range("G3").Value = RunLength
ActiveSheet.Range("D3").Value = ResistanceValue
ActiveSheet.Range("E3").Value = 1 / ResistanceValue
runTotal = runTotal + RunLength
resistTotal = resistTotal + ResistanceValue
If i = Range("C2").Value Then
ActiveSheet.Range("G4").Value = runTotal
ActiveSheet.Range("D4").Value = runTotal
End If
Next i
Dim runArr() As Double
ReDim runArr(1 To QtyEntry)
For i = 1 To Range("C2").Value
'...
runArr(i) = RunLength
Next i
如果这不能解决您的问题,并且您希望使用阵列,则可以添加类似于以下内容的内容:
Dim i As Integer
Dim runTotal As Double
Dim resistTotal As Double
runTotal = 0
resistTotal = 0
For i = 1 To Range("C2").Value
Rows("3").Insert Shift:=xlShiftDown, CopyOrigin:=xlFormatFromRightOrBelow
ResistanceValue = InputBox("Hey dude, what is the resistance value in ohms?")
RunLength = InputBox("Cool! How far is it (in feet) from the previous load? Use distance from voltage source if this is the first load.")
ActiveSheet.Range("G3").Value = RunLength
ActiveSheet.Range("D3").Value = ResistanceValue
ActiveSheet.Range("E3").Value = 1 / ResistanceValue
runTotal = runTotal + RunLength
resistTotal = resistTotal + ResistanceValue
If i = Range("C2").Value Then
ActiveSheet.Range("G4").Value = runTotal
ActiveSheet.Range("D4").Value = runTotal
End If
Next i
Dim runArr() As Double
ReDim runArr(1 To QtyEntry)
For i = 1 To Range("C2").Value
'...
runArr(i) = RunLength
Next i
如果您正在学习VBA,我强烈建议您使用
选项Explicit
。您正在使用各种未声明的变量。此外,请尝试一致地缩进代码。你发布的内容很难阅读。使用一系列输入框将值加载到电子表格的循环对大多数用户来说都很烦人(这种烦扰不太可能通过重复的“嘿,伙计”来减轻)。为什么不让用户直接将值输入电子表格,然后让VBA代码读取它们(可能在用户选择要处理的值之后)?嗨,John,我该如何让VBA代码读取它们?如果您正在学习VBA,我强烈建议使用Option Explicit
。您正在使用各种未声明的变量。此外,请尝试一致地缩进代码。你发布的内容很难阅读。使用一系列输入框将值加载到电子表格的循环对大多数用户来说都很烦人(这种烦扰不太可能通过重复的“嘿,伙计”来减轻)。为什么不让用户直接将值输入电子表格,然后让VBA代码读取它们(可能是在用户选择要处理的值之后)?嗨,John,我该如何让VBA代码读取它们?