久久久国产一区二区_国产精品av电影_日韩精品中文字幕一区二区三区_精品一区二区三区免费毛片爱

 找回密碼
 注冊會(huì)員

QQ登錄

只需一步,快速開始

搜索
查看: 1627|回復(fù): 3

excel 中BVA 麻煩大佬幫忙解釋一下

[復(fù)制鏈接]
1#
發(fā)表于 2022-6-6 18:03:11 | 只看該作者 |倒序?yàn)g覽 |閱讀模式
Option Compare Text
3 q/ I  K  q7 U% o9 i1 {% ]0 j- x8 N' O1 e  l
Public Function GSXS(Ref)# b4 h3 s- N6 W8 E
& {( a( y' p( A# F6 c
    GSXS = Ref.Formula
6 ^( q% ]7 ]  O* V" g5 G
6 h" p+ y) q5 F& z, A3 {0 ]End Function5 e8 E5 o, F) G' J& y+ ?; ^
5 S  E: \, V1 [/ ?
Public Function ZZL(RowHead, ColHead, Dummy)" ~- C: Y9 ~4 s8 K2 r# ^
, F) i# P! a2 o# S* S5 ~7 w
Dim Values(20) As Variant% H6 e+ C3 H7 u% `
Dim PrevData(20) As Variant
9 _- h0 A- y0 [/ X6 L  xDim LE(20) As Integer
  \& u4 J: D& C; Y8 `, F, L6 t
# d: x- b7 M( g7 GOn Error GoTo err_handler1- E. Z" M6 n! d( W
' Do the vertical selection from rows
4 y5 M2 G; F# S3 E! V0 N, bIf RowHead.Rows.Count = 1 Then( A3 `- p  I" M0 u8 d
    rindex = RowHead.Row    ' first argument is any cell on the row of possible values; z. z) ]5 C* D0 Z% T' B2 A
Else
' P% y/ [: X% N    ' Store the values to be compared with each column
& f8 E' ^8 y/ S, K    For ii = 1 To RowHead.Columns.Count8 L* ?0 e/ _% Q: O& ~. T
        rngname = RowHead.Cells(1, ii)/ _/ N, @/ f/ E
        LE(ii) = InStr(rngname, "<=")# X! w  W! s0 g( C4 _0 C& @9 o& v
        If LE(ii) > 0 Then" v: `, v" U% ^5 T
            rngname = Mid(rngname, 1, LE(ii) - 1)
- q& p# i' R" j: A$ h. F        End If6 X9 y: d9 r, I
        Values(ii) = Range(rngname)- Y. I, H+ q, v
        'debug.Print "Variable:" & rngname & " is:" & Values(ii)
4 [9 I% _- }6 Y% O3 U* b. u        PrevData(ii) = ""   ' initialise
' X2 J4 x5 m9 a3 i1 @    Next ii
* P. h& j6 {* |- |6 Z: \
' l# N/ ~! p& t  {+ n5 Q) |1 ^) N    rindex = 2
6 Y2 _8 W  M9 p. x9 F    'debug.Print RowHead.Columns.Count
( ?) I6 _+ D6 X3 I    Match = False
0 t5 ~7 k" A% @2 [+ w4 g/ V    For r = rindex To RowHead.Rows.Count
1 w) B2 P. z% F7 B- d; l$ x% P' X        For c = 1 To RowHead.Columns.Count   ' for each dimension8 M# }, R* z  P" Q0 B
            data = RowHead.Cells(r, c), n$ B* E2 t+ E5 ]4 o- c
            If data = "" Then
0 [( S0 B/ S( V8 [* d                'debug.Print "Empty cell found: using " & PrevData(c)8 @- [# q4 O6 O- j
                ' use the last valid cell in this column* n# T% O4 T7 `
                ' (this is to handle merged cells)
5 B# w. r* U( }2 o7 J                data = PrevData(c)
( J1 t1 b& r; n& R* n* {            End If
+ E5 I3 W" x* {0 c) u+ h8 i7 G. Z            'debug.Print "data:" & data
% U$ r& a, l6 a3 x' U; R            PrevData(c) = data ' save for use by empty cells
3 E, s8 Z$ B  U4 N# Z) Y, e            If data = Values(c) Or (data > Values(c) And LE(c) > 0) Or data = "*" Then0 |2 N& h$ {" y" s* r
                If c = RowHead.Columns.Count Then   ' All columns match - It's a go: O5 N1 U1 W! g; i
                    Match = True
$ M! E: S& r; B% V1 Q$ H% j                End If' F. C8 r) p. J& l3 |6 x5 g, n
            Else    ' This column doesn't match - go to the next row* F; T$ g% d. N; t" O  z; i
                Match = False
- E$ O# n: E# Q" T* w+ r' W                Exit For
3 f0 n& }% J9 h4 [8 {8 P            End If- p2 v$ J, g4 J3 _
        Next c
+ \# ^: L+ [# Z. {! m1 ]/ Y' S/ {9 u        If Match = True Then    ' Don't search any more rows
! f5 J6 b4 I+ t5 z8 [8 m( T) C1 H) n            rindex = r
0 [( z* }; k" d2 L            Exit For2 f% Y2 ^6 {0 B6 E9 C' u$ l  k
        End If0 _/ c, g) `! `. p) _2 X+ v
    Next r0 b7 m/ O" {7 X. M; X
! j8 v2 R, u+ ?0 O: r7 m+ N
    If Match = False Then   ' Didn't find a matching set of values
( ]/ w* @2 g3 P  X1 J        ZZL = "No match for rows"
& ~' l& L* n: {8 b* R! |5 z, r3 j        Exit Function
# |' L' q! }# h3 ~  y    End If
1 v% d7 q3 h3 x6 m3 Z+ z- ]
% w/ @7 y* \$ Q: B/ C8 p. k    rindex = rindex + RowHead.Row - 1   ' make absolute index
% a3 s* [2 S- Y: |End If
* `5 ?- A: i& Y3 T
0 n6 }' M# `* T' Do the horizontal selection from columns) W* b) y* g& b! A
If ColHead.Columns.Count = 1 Then* z* |; G2 \' G, f& Q
    cindex = ColHead.Column( c5 y  [7 P8 C6 |9 g
Else+ U0 S; U4 a, }9 ?  s! M: C/ d# T& S
    ' Store the values to be compared with each row of the header
. x- R5 ^" A8 u5 A# j8 k( d    For ii = 1 To ColHead.Rows.Count
' b. j& `/ R. K+ y2 X1 Y        rngname = ColHead.Cells(ii, 1)' n* y; w& C3 B+ l$ r+ @- q0 W
        LE(ii) = InStr(rngname, "<=")
7 W  S* V9 j) T+ O1 O3 `        If LE(ii) > 0 Then
! J" N' z% O0 y0 G( l; ~            rngname = Mid(rngname, 1, LE(ii) - 1)! K3 W2 M; N. J- t
        End If. a: A# s7 x* u- L1 G
        Values(ii) = Range(rngname): |3 m2 `7 p) X0 K- h$ U# U% x9 `
        'debug.Print "Variable:" & rngname & " is:" & Values(ii)
9 D; ~+ |& b3 j( y; s' p        PrevData(ii) = ""   ' initialise2 v! `" D. f/ ]" f
    Next ii5 r* ?" H4 R+ n  y6 N% B# A9 s

; N/ @4 g+ y% Y5 h    cindex = 2* s# f7 x; C4 T  U) J
    'debug.Print ColHead.Columns.Count
# s/ ~% h* i/ H1 V7 t) ~1 P3 U    Match = False7 K0 M- z* d2 c4 [
    For c = cindex To ColHead.Columns.Count" p' y. W' ]( g- P) V* g
        For r = 1 To ColHead.Rows.Count   ' for each dimension
. L5 i# Q3 |1 x) d! G- P            data = ColHead.Cells(r, c)
: l, k0 E0 v( ^& |4 s+ R( F            If data = "" Then8 o$ t7 O  B1 W
                'debug.Print "Empty cell found: using " & PrevData(r)
- b) u! w4 X4 N                ' use the last valid cell on this row
" J0 C7 Q- A6 \- ^7 E; {( ~$ r                ' (this is to handle merged cells)
  A2 _* @" m0 s* M: F7 Y) Q                data = PrevData(r)
0 ]. m$ {( y# W' Q! S& F            End If: w/ v6 u! D/ m3 c
            'debug.Print "data:" & data
& Q. {8 B- u' |/ I# P% _& Z# P            PrevData(r) = data ' save for use by empty cells  U1 q& P; |) F3 O. K# E. W
            If data = Values(r) Or (data > Values(r) And LE(r) > 0) Or data = "*" Then
5 y7 [, v1 j! v$ B                If r = ColHead.Rows.Count Then   ' All rows match - It's a go
, v4 A1 V1 j& @                    Match = True
- |  I' R6 e, \$ z7 y                End If: g- S% A/ ~5 g7 @6 j
            Else    ' This row doesn't match - go to the next column
3 Z% T8 P  a: s; T. T' n9 S                Match = False
4 Q: `0 F) r% q6 O! Y                Exit For1 a, G* n4 R; Z& ^+ f
            End If
8 U* _7 {/ E9 W, V7 F. h        Next r
4 C% _2 [) Q" }) `# R) j        If Match = True Then    ' Don't search any more columns1 r* a& t' M  ^8 B: k( O5 @: R
            cindex = c' k& f  x/ Y$ w( ~
            Exit For* N: l% o1 X* A; _- Y5 Q
        End If0 G$ _" e( F+ n& d4 K
    Next c
! U5 h# ]6 e3 s% W; I; v
6 g2 n) J% m: A& R+ n' X    If Match = False Then   ' Didn't find a matching set of values3 I" V1 _+ G& ?  k
        ZZL = "No match for columns"
2 {, F2 d' a: U5 g" h        Exit Function
  @( j5 X9 g8 h* [4 p$ B/ ]; i    End If* a: H8 K/ m3 t
1 ?+ c; {4 {1 D7 X& p
    cindex = cindex + ColHead.Column - 1
2 K+ |: W+ y  a- iEnd If* ~+ j. b- D+ X% r- |7 x1 x; e: J  {
8 h+ O' {5 p3 K( W2 C  V; G
' Return the cell value from Table
, J% Y6 n+ ~. M1 @'debug.Print "Answer is in (R,C):  " & rindex, cindex1 ^6 P/ e$ ~* g) D7 w/ K
ZZL = ActiveSheet.Cells(rindex, cindex)2 B. _8 e) `6 g, i2 i
'debug.Print "Answer is : " & ZZL
- l$ L' v% |) g( D' v, \Exit Function
6 X0 o/ E0 ?1 W1 _2 T% x0 r; N2 G& Y0 y, R! C3 }3 N- R
err_handler1:
" u" c" s/ h  m" z) x% P+ c# QZZL = "Error on range '" & rngname & "'"
7 E" d6 O: {' g; g) k  |( [5 D+ o: C1 v8 N0 e
End Function
; ~3 {  F/ U5 K$ X3 N" ^# J( [8 q" h8 A- J$ u
回復(fù)

使用道具 舉報(bào)

2#
 樓主| 發(fā)表于 2022-6-6 18:04:26 | 只看該作者
本人是小白,想請教大佬,如何能看懂以上信息
3#
發(fā)表于 2022-6-6 19:17:09 | 只看該作者
微軟官方的bbs里是有專業(yè)的VBA教程和API端口說明能檢索的(全英文)
4#
發(fā)表于 2022-6-7 08:52:01 | 只看該作者
上excel論壇問問看
您需要登錄后才可以回帖 登錄 | 注冊會(huì)員

本版積分規(guī)則

Archiver|手機(jī)版|小黑屋|機(jī)械社區(qū) ( 京ICP備10217105號-1,京ICP證050210號,浙公網(wǎng)安備33038202004372號 )

GMT+8, 2025-7-20 00:43 , Processed in 0.070950 second(s), 14 queries , Gzip On.

Powered by Discuz! X3.5 Licensed

© 2001-2025 Discuz! Team.

快速回復(fù) 返回頂部 返回列表