[英]Excel Vba: Select and trend routine
So I have a table like this, assume Tidal Height is B1: 所以我有一张这样的桌子,假设潮汐高度为B1:
Tidal Time Tidal Height
00:00:00 4.40
01:00:00
02:00:00
03:00:00
04:00:00
05:00:00
06:00:00 2.00
07:00:00 2.50
08:00:00 3.00
09:00:00 3.50
10:00:00 4.00
11:00:00 4.50
12:00:00
13:00:00
14:00:00
15:00:00
16:00:00
17:00:00
18:00:00 2.10
19:00:00 2.56
20:00:00 3.02
21:00:00 3.48
22:00:00 3.94
23:00:00 4.40
So I need to do this: 所以我需要这样做:
1st Step: Select the first occupied cell from B2, and select up till (and including) the next occupied cell. 第一步:从B2中选择第一个被占用的单元格,然后选择直到(包括)下一个被占用的单元格。 Then run this code:
然后运行以下代码:
RangeToFill.DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay, Trend:=True
2nd Step: Deselect, then continue and select the cell before the next empty cell. 第二步:取消选择,然后继续并选择下一个空单元格之前的单元格。 Select up till (and including) the next occupied cell.
选择直到(包括)下一个占用的单元格。 Then run the trend code above.
然后运行上面的趋势代码。
I can do this by hand, but i'm unsure how to automate the process like this to take in account the changing data sets in different positions. 我可以手动完成此操作,但是我不确定如何将这样的过程自动化,以考虑到不同位置上不断变化的数据集。 Any help would be appreciated please!
任何帮助将不胜感激!
Dim Bounds As Range
Set Bounds = Range("A1").CurrentRegion
Dim c As Range
Set c = Range("B2")
Do While c.Row < Bounds.Rows(Bounds.Rows.Count).Row
If IsEmpty(c.Offset(1, 0).Value) Then
Dim RangeToFill As Range
Set RangeToFill = Application.Intersect(Range(c, c.End(xlDown)), Bounds)
RangeToFill.DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay, Trend:=True
Set c = RangeToFill.Cells(RangeToFill.Cells.Count)
Else
Set c = c.End(xlDown)
End If
Loop
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.