您如何找到从输入框输入的值的行,然后使用它来定义。选择数据范围?
我难以执行以下代码块。我一直遇到400个错误,这是非常新的。基于以下代码的任何建议将不胜感激。我有一种感觉可能正在使用块功能和潜艇的不正确形式。再次感谢您的任何输入! - 问候
Sub InputTestParameters1()
' Ask user for the test start time and test length, return values
' Use the returned values to calculate the End time.
' Using the start and end times, find them in data contained in column B, and return the Row Values.
' Use the Row Values to select data to be copied and pasted in other columns.
Dim test_length As Integer
Dim Time_start As Integer
Dim Time_end As Integer
Dim row_start As Integer
Dim test_time As Integer
Dim row_end As Integer
' Calculate the end time based on user input of start time and length of test.
Time_start = InputBox("Enter the time in seconds from the" & Chr(10) _
& "start of the test that you would" & Chr(10) _
& "like to be the test start.", "Test Start")
test_length = InputBox("Enter the Length of the test in hours", "Test Length")
Time_end = (test_length * 3600) + Time_start
' Find the row of the test time
row_start = Application.WorksheetFunction.Match(Time_start, Range("B:B"), 0)
row_end = Application.WorksheetFunction.Match(Time_end, B, 0)
' Select the temperature data range and copy and paste it into the temps worksheet
Sheets("Data Import").Range(Cells((row_start), 7), Cells((row_end), 11)).Select
' Copy and paste the Temps Data from the selected Start and End times.
'Range("G3:K68").Select
Selection.Copy
Sheets("Temperatures UNIVERSAL").Select
Range("C7").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.SmallScroll Down:=-15
row_num = 0
test_time = 0
row_end = 0
End Sub
I am having trouble getting the following block of code to perform. I keep getting the 400 error and am very new to this. Any suggestions based on the code below would be highly appreciated. I have a feeling I may be using the incorrect form of block functions and subs. Again thank you for any input you may have! - Regards
Sub InputTestParameters1()
' Ask user for the test start time and test length, return values
' Use the returned values to calculate the End time.
' Using the start and end times, find them in data contained in column B, and return the Row Values.
' Use the Row Values to select data to be copied and pasted in other columns.
Dim test_length As Integer
Dim Time_start As Integer
Dim Time_end As Integer
Dim row_start As Integer
Dim test_time As Integer
Dim row_end As Integer
' Calculate the end time based on user input of start time and length of test.
Time_start = InputBox("Enter the time in seconds from the" & Chr(10) _
& "start of the test that you would" & Chr(10) _
& "like to be the test start.", "Test Start")
test_length = InputBox("Enter the Length of the test in hours", "Test Length")
Time_end = (test_length * 3600) + Time_start
' Find the row of the test time
row_start = Application.WorksheetFunction.Match(Time_start, Range("B:B"), 0)
row_end = Application.WorksheetFunction.Match(Time_end, B, 0)
' Select the temperature data range and copy and paste it into the temps worksheet
Sheets("Data Import").Range(Cells((row_start), 7), Cells((row_end), 11)).Select
' Copy and paste the Temps Data from the selected Start and End times.
'Range("G3:K68").Select
Selection.Copy
Sheets("Temperatures UNIVERSAL").Select
Range("C7").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.SmallScroll Down:=-15
row_num = 0
test_time = 0
row_end = 0
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是代码下半部分的快速重写。目前尚不清楚您使用哪个纸来查找比赛。请记住,当您不指定工作表时,它将使用可能打算或可能是可能的活动表。另一个注意事项,搜索行时最好使用长时间而不是整数。超过100万行和整数限制为32,767。
Here is a quick rewrite of the lower half of your code. It is not clear which sheet your are using to find the match. Keep in mind that when you do not specify the sheet, it will use the active sheet, which may or may be intended. One other note, when searching rows it is best to use Long instead of integer. There are over 1 million rows and Integer caps out at 32,767.