我好像贝壳吧 关注:97贴子:5,970
  • 1回复贴,共1

【vba】excel中根据表名、行名、列名取对应数据的函数

只看楼主收藏回复

Function FINDLR(table, row, line)
'FINDLR = Application.WorksheetFunction.VLookup(name, Sheets(table).Range("A:ZZ"), line, 0)
'表格范围:行最大值MAXROW 列最大值MAXLINE
Dim MAXROW, MAXLINE As Long
MAXROW = 1000
MAXLINE = 255
'获取对应table中第一个不为空的行列 i:行 j:列
Dim i, j As Long
For i = 1 To 1000
If Sheets(table).Cells(i, 1).Value <> "" Then
For j = 1 To 255
If Sheets(table).Cells(i, j).Value <> "" Then
Exit For
End If
Next
Exit For
End If
Next
Dim i2, j2 As Long
Dim find As Boolean
find = False
'先确定行中是否存在row
For i2 = i To 1000
If Sheets(table).Cells(i2, j).Value = row Then
'存在row,再取line
For j2 = j To 1000
If Sheets(table).Cells(i, j2).Value = line Then
find = True
Exit For
End If
Next
Exit For
End If
Next
If find = True Then
FINDLR = Sheets(table).Cells(i2, j2)
Else
FINDLR = ""
End If


1楼2017-04-20 21:44回复
    单击事件
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Value = "" Then
    Target.Value = "√"
    Else
    If Target.Value = "√" Then
    Target.Value = ""
    End If
    End If
    End Sub


    IP属地:福建2楼2017-04-23 19:20
    回复