你如何找到从输入框输入的值所在的行,然后用它来定义 .select 数据范围?
How do you find the row a value entered from inputbox is in, and then use it to define .select data range?
我无法执行以下代码块。我不断收到 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
这里是对代码下半部分的快速重写。目前尚不清楚您使用哪个 sheet 来查找匹配项。请记住,当您未指定 sheet 时,它将使用活动的 sheet,这可能或可能是预期的。另外请注意,在搜索行时最好使用 Long 而不是整数。有超过 100 万行,Integer 上限为 32,767。
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Set ws1 = ThisWorkbook.Worksheets("Data Import")
Set ws2 = ThisWorkbook.Worksheets("Temperatures UNIVERSAL")
ws1.Range(ws1.Cells((row_start), 7), ws1.Cells((row_end), 11)).Copy
ws2.Range("C7").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
我无法执行以下代码块。我不断收到 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
这里是对代码下半部分的快速重写。目前尚不清楚您使用哪个 sheet 来查找匹配项。请记住,当您未指定 sheet 时,它将使用活动的 sheet,这可能或可能是预期的。另外请注意,在搜索行时最好使用 Long 而不是整数。有超过 100 万行,Integer 上限为 32,767。
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Set ws1 = ThisWorkbook.Worksheets("Data Import")
Set ws2 = ThisWorkbook.Worksheets("Temperatures UNIVERSAL")
ws1.Range(ws1.Cells((row_start), 7), ws1.Cells((row_end), 11)).Copy
ws2.Range("C7").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False