Enter number into a cell and search an array for t

2019-09-17 03:29发布

I am reconciling accounts and was wondering if there is a formula/VBA I can use to search for certain values, as the find function doesn't work?

For example: enter -54.12 into a cell, formula/VBA searches an array for that number.

This may explain better what I'm trying to achieve, albeit more of an explanation than coding:

Sub Test()

Dim Value As Integer
Dim Account As Range
Dim Lookup As Boolean

Value = Range("D8")
Account = Range("E:E")

Set Value = A
Set Account = B
' IF A is present in B then look up = true
' if look up is true then scroll to cell

End Sub

I could then set a Private Sub by value change to do the same thing each time a new value is entered?

1条回答
冷血范
2楼-- · 2019-09-17 03:51

Lifted directly from https://stackoverflow.com/a/19126873/1505120 (where I forgot to mention the search term goes in G1):

Lifted direct from MrExcel

Assuming data array is in A1:D5:

In G2: =COUNTIF(B2:D5,G1)

In G4: =IF(ROWS($G$4:G4)>$G$2,"",INDEX($A$2:$A$5,INT(SMALL(IF($B$2:$D$5=$G$1,(ROW($B$2:$D$5)-ROW($B$2)+1)*10^5+COLUMN($B$2:$D$5)-COLUMN($B$2)+1),ROWS($G$4:G4))/10^5)))

In H4: =IF(ROWS($G$4:G4)>$G$2,"",INDEX($B$1:$D$1,MOD(SMALL(IF($B$2:$D$5=$G$1,(ROW($B$2:$D$5)-ROW($B$2)+1)*10^5+COLUMN($B$2:$D$5)-COLUMN($B$2)+1),ROWS($G$4:G4)),10^5)))

The latter two entered with Ctrl+Shift+Enter and copied down.

查看更多
登录 后发表回答