Excel - 自动填充趋势值

时间:2015-08-20 12:26:51

标签: excel

这是我到目前为止的代码:

Sub Tele()

    Dim rowLoop As Long
    rowLoop = 1
    strValueToFind = Application.InputBox("Enter a Search value in format xx.xx.xxxx, remember that this will only work if you are on 'Tidal' tab", Title:="DATE FIND", Default:=Format(Date, "Short Date"), Type:=1)

    'Select the sheets to work through
    Sheets(Array("2015", "2016", "2017", "2018", "2019", "2020")).Select

    For Each ws In ActiveWindow.SelectedSheets

      Debug.Print "Checking " & ws.Name

      ' Loop column A to find value, number corrosponds to letter position in alphabet
      For rowLoop = 1 To Rows.Count
        If ws.Cells(rowLoop, 1).Value = strValueToFind Then ' If value is in C then do something
          ' start on cell found from date needed - look at copying range on same Column
          ' -------------------------------------------------------------------------------------------'
          Sheets("Vessels").Range("C09").Value = ws.Cells(rowLoop, 1).Offset(0, 1).Resize(1).Value
          Sheets("Vessels").Range("C10").Value = ws.Cells(rowLoop, 1).Offset(0, 3).Resize(1).Value
          Sheets("Vessels").Range("C11").Value = ws.Cells(rowLoop, 1).Offset(0, 5).Resize(1).Value
          Sheets("Vessels").Range("C12").Value = ws.Cells(rowLoop, 1).Offset(0, 7).Resize(1).Value
          Sheets("Vessels").Range("C14").Value = ws.Cells(rowLoop, 1).Offset(1, 2).Resize(1).Value
          ' Copy cells 1 cell below found value - Montrose?
          Sheets("Vessels").Range("D09").Value = ws.Cells(rowLoop, 1).Offset(0, 2).Resize(1).Value
          Sheets("Vessels").Range("D10").Value = ws.Cells(rowLoop, 1).Offset(0, 4).Resize(1).Value
          Sheets("Vessels").Range("D11").Value = ws.Cells(rowLoop, 1).Offset(0, 6).Resize(1).Value
          Sheets("Vessels").Range("D12").Value = ws.Cells(rowLoop, 1).Offset(0, 8).Resize(1).Value
          MsgBox ("Found value on col " & rowLoop) '
          Exit Sub
        End If
      Next rowLoop ' This is row number, do something with this

    'Back for next sheet
    Next ws

    ' This MsgBox will only show if the loop completes with no success
    MsgBox ("Date not found, make sure you have input the date correctly and on the right tab")

End Sub

该程序允许用户输入日期并返回当天的潮汐时间和高度。此外,用户需要输入时间并返回相应的潮汐高度。问题是我只有4个值,而不是每一天的值。所以考虑一下:

说我有这样一张桌子:(假设潮汐时间是A,潮汐高度是B)

Tidal Time  Tidal Height  
01:00   
02:00   
03:00   
04:00   
05:00            5  
06:00   
07:00   
08:00   
09:00   
10:00   
11:00            1.2  
12:00   
13:00   
14:00   
15:00   
16:00   
17:00            5.2  
18:00   
19:00   
20:00   
21:00   
22:00   
23:00            1.1  
00:00   

是否可以根据输入的值填写未知值 注意: 只填写了3或4个值 对于不同的数据集,它们出现在不同的时间。

实际上我已经通过使用填充右键单击系列(趋势)命令完成了这项工作,我需要做的就是在这些值发生变化后自动运行。

澄清:
'fil in'指的是B列中的未填充值。类似..它需要从输入到下一个值的任何值趋势,反之亦然。如果你愿意的推断。此外,它需要根据填充的单元格自动发生

此功能的编写原因就像我可以管理的那样:
数据每天给出4个值。 - 4次和4次潮汐高度 - 用户输入日期,这4个值填写在最近时间旁边的B处 - 表格需要外推以填写未写入的值 - 然后当时间被放入。它用B中的所有值检查时间。返回值(潮汐高度)上3.2以上的任何东西与输入时间相对应给出“是”,下面的任何内容都给出“否” “

等效预测: 因此,对于我给出是或否的最后一部分,我正在考虑预测函数:=FORECAST(00:45,A10:A33,B10:B33)
00:45是用户输入的时间,并且对B中输入的信息进行预测。理想情况下,我需要相当于VBA的VBA,以便00:45的值为Application.InputBox

1 个答案:

答案 0 :(得分:0)

根据您估算值的基础输入公式,例如如果它是线性的:

(单元格引用假设示例的左上角是A1)

B7中的

: = B6 - (($ B $ 6- $ B $ 12)/ 6)

然后向下拖动到下一个数字。然后为B12和B18做同样的事情,依此类推。值将自动更新。

编辑:要回答问题的其他部分,您需要在四舍五入到最近的小时后查找时间。例如,如果在D35中输入日期,并且问题中给出的表格是sheet1:

查找(D35,工作表Sheet $ A $ 1:$ A $ 24,3,1)

如果这不起作用,请检查所有时间是否实际格式化为次。如果您需要舍入到最近的小时,请尝试TIME(小时(D35)+ IF(分钟(D35)> 30,1,0),0,0)

然后,在C列中使用if语句来辨别这些值是否大于3.2,例如在C2:= IF(B2> 3.2,"是","不")

查找应返回yes或no。