您如何找到从输入框输入的值的行,然后使用它来定义。选择数据范围?

发布于 2025-01-23 12:05:18 字数 1869 浏览 0 评论 0原文

我难以执行以下代码块。我一直遇到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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光匆匆的小流年 2025-01-30 12:05:18

这是代码下半部分的快速重写。目前尚不清楚您使用哪个纸来查找比赛。请记住,当您不指定工作表时,它将使用可能打算或可能是可能的活动表。另一个注意事项,搜索行时最好使用长时间而不是整数。超过100万行和整数限制为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

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.

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文