使用另一个表作为参考

时间:2016-05-14 23:21:12

标签: excel vba

我使用excel监控我的学习习惯。我有一张像

这样的表格

表1:

| Start Time | End Time | Date   | Pages |
|------------|----------|--------|-------|
| 07:40:00   | 08:00:00 | 12 May | 12    |
| 08:13:00   | 08:25:00 | 12 May | 5     |
| 08:40:00   | 08:55    | 12 May | 8     |

如您所见,在一行的结束时间和下一行的开始时间之间存在间隔。那是因为我通常会被互联网分心。我知道如何将Google Chrome历史记录添加到格式表中 -

表2:

| Time Visited | URL Visited               |
|--------------|---------------------------|
| 08:03:00     | https://www.reddit.com/   |
| 08:08:00     | https://www.facebook.com/ |
| 08:28:00     | https://www.youtube.com/  |
| 08:32:00     | https://www.facebook.com/ |
| 08:34:00     | https://www.reddit.com/   |

显然有更多的网址。我正在寻找一种方法,如果我点击表1中的一行(在excel中),表2将过滤到该行的End TimeStart Time之间访问过的网站。下一行。我是一个优秀的菜鸟,并且尽可能地避免使用VBA,但如果有人能为我提供任何解决方案,我将不胜感激。还有像数据透视表等可以在这里使用的数据结构吗?

由于

1 个答案:

答案 0 :(得分:0)

整晚都在学习VBA。解决了这个问题!

解决方案表(转到名为“MySheet”的第二张表) -

https://drive.google.com/file/d/0Bx5DxTdpRXyyekZlenlxSTZsTW8/view?usp=sharing

代码(包含在excel中)=

Function GetColumnName()
    Dim rowHeader As Integer
    Dim colCurrent As Integer
    Dim name As String
    rowHeader = ActiveCell.ListObject.Range.row
    colCurrent = ActiveCell.Column
    name = Cells(rowHeader, colCurrent).Value
    GetColumnName = name
End Function


Function GetNeighborCell(colName As String)
    Dim firstCol As Integer
    Dim offsetCol
    Dim col
    Dim row As Integer
    Dim val As String

    firstCol = ActiveCell.ListObject.Range.Column
    offsetCol = ActiveCell.ListObject.ListColumns(colName).index - 1
    col = firstCol + offsetCol

    row = ActiveCell.row
    val = Cells(row, col).Value
    GetNeighborCell = Cells(row, col).Address
End Function

辅助函数

proc1 PROC  USES ecx
        mov al, 'A'         ;Stores characther              
L1:     call WriteChar      ;Writes character
        inc al              ;Increment al
        loop L1
        ret
proc1 ENDP
相关问题