机械必威体育网址

找回密码
注册会员

QQ登录

只需一步,快速开始

搜索
查看: 1127 | 回复: 3
打印 上一主题 下一主题

excel 中BVA 麻烦大佬帮忙解释一下

[复制链接]
跳转到指定楼层
1#
发表于 2022-6-6 18:03:11 | 只看该作者 回帖奖励 | 倒序浏览 | 阅读模式
Option Compare Text2 @: e; z: Z# M( ~# g. h/ Y. c) d! w) o
D3 Q0 X8 R1 D/ X! S D5 h3 R
Public Function GSXS(Ref)
0 P7 j) ?8 j2 @- X/ a) y- E, |5 |1 t
GSXS = Ref.Formula, C5 ~/ h) s5 J N9 m1 a7 p

( l6 e- N" y# b, J! @End Function: A- r/ B: B( I; S6 M* |. O
5 X- b, h6 c& Y3 R; Z; }
Public Function ZZL(RowHead, ColHead, Dummy)
- q K9 W2 O5 F. v: f/ a
! ^8 Q4 A% m* u% ]# XDim Values(20) As Variant
! x3 z0 I: T. F2 ?2 H0 l/ W2 |/ dDim PrevData(20) As Variant
0 {% r L/ U: K7 D! C" g3 L# B7 }$ KDim LE(20) As Integer& i' X' a- o' I( V& K2 v

H1 ?* `9 j% t. ?On Error GoTo err_handler1
# Z9 I3 p% B9 J+ a5 J M' Do the vertical selection from rows- S4 m. T8 U/ [0 C0 b" y- b
If RowHead.Rows.Count = 1 Then
6 o7 V4 a( I: a* _0 Urindex = RowHead.Row ' first argument is any cell on the row of possible values7 c- u+ J( J$ E+ ~ ~) k1 e
Else
* C' l5 h+ @6 }+ m' Store the values to be compared with each column3 w8 k* V' M* ]4 P4 E, i
For ii = 1 To RowHead.Columns.Count
9 f; s8 f: D- a( L& jrngname = RowHead.Cells(1, ii)
' | N+ R) R1 ]' p& PLE(ii) = InStr(rngname, "<=")/ P7 t% H2 J$ d$ z9 i5 J' a& P* ^
If LE(ii) > 0 Then
- L0 }5 P m! ^, e8 f7 ]* arngname = Mid(rngname, 1, LE(ii) - 1)% v5 y* ^' n$ k2 C) q X7 {
End If7 {; d' f! H( v2 a. I, y) z! A
Values(ii) = Range(rngname)
4 [6 s2 R |/ l4 C; j# n8 [! ]'debug.Print "Variable:" & rngname & " is:" & Values(ii)
$ N3 c5 j! \+ c( I: W4 T) o/ p8 CPrevData(ii) = "" ' initialise3 i2 l0 B0 A, c* u) \! y
Next ii
3 ~9 [' ~: \: g5 D6 M8 w; W) C! Z% m0 J# ?) i; x" S
rindex = 27 I. T. w; j* s6 Z' x
'debug.Print RowHead.Columns.Count: J; D2 y F' u' g* `- G, r7 d5 p2 e
Match = False! P# g1 Q' r. |4 C) K2 [# `& B
For r = rindex To RowHead.Rows.Count* Z4 V4 r7 M* P8 r
For c = 1 To RowHead.Columns.Count ' for each dimension
- w% S- \1 C5 qdata = RowHead.Cells(r, c)
% m1 ?5 S2 x4 `7 p$ U; PIf data = "" Then* {6 [* x8 S( Q' x1 i( }3 P; f7 j
'debug.Print "Empty cell found: using " & PrevData(c)
! S. p) d% P7 a6 S+ ]# l! T0 k' use the last valid cell in this column
4 K* e3 B r2 {; p' (this is to handle merged cells)
, ~7 k6 H0 ]; s5 B# Wdata = PrevData(c)
+ m9 B+ l) n. ?7 G3 H* nEnd If+ o2 C, r- y. J9 ]
'debug.Print "data:" & data6 p+ [% T! J' W6 Q. W& Z, m
PrevData(c) = data ' save for use by empty cells( [- g' U ]& W2 R* m+ |, w0 V
If data = Values(c) Or (data > Values(c) And LE(c) > 0) Or data = "*" Then
$ ?- d! ?9 q6 X* ?( D& ~If c = RowHead.Columns.Count Then ' All columns match - It's a go
( H; Q) u8 t3 G4 c1 n2 SMatch = True" G% e# S% G Z) N2 j% P: [% F, t1 _) H
End If
0 b9 s- m4 { }! U! H, zElse ' This column doesn't match - go to the next row. N& b8 |( K& M, g, D
Match = False6 X) p. ~+ d& i+ _6 m* w
Exit For
7 u. B0 y1 q9 X* ]$ VEnd If; m5 q4 l) R# K8 i9 e' Q4 M+ o
Next c
3 [2 E8 Z: i ~0 P$ _! wIf Match = True Then ' Don't search any more rows
8 y2 `6 x! V( v# S- g0 brindex = r
' Z1 v3 v* i' l5 E! BExit For
( j+ r3 L% d% K5 WEnd If0 w) I9 Y8 B+ b) _
Next r
% t' T! ^7 \( K0 A3 I# _
. m' M% o2 Y1 U2 |5 tIf Match = False Then ' Didn't find a matching set of values
+ j. [% X f$ ?! y. A& a8 i3 kZZL = "No match for rows"
+ ?) O$ Q' F; {6 s. L0 bExit Function
8 x/ F( c2 g+ l3 A9 b; dEnd If
. f$ U% e7 R% I3 |. k, r$ k
3 v4 F' d- y/ @7 n# V3 v* zrindex = rindex + RowHead.Row - 1 ' make absolute index
1 U* @ R3 u& T9 h6 R/ {& H1 zEnd If
! f$ r. x: O7 ~
" D8 z$ @& O5 d1 L+ T3 ~' Do the horizontal selection from columns" b( c6 s* B5 W6 @" B! l
If ColHead.Columns.Count = 1 Then
+ F% E. p& W# B; k7 ?/ pcindex = ColHead.Column/ E9 k9 P& z# n- I K
Else+ S/ Z' G$ U: L) N% M: d9 [
' Store the values to be compared with each row of the header5 O7 i; s) c! [5 O$ O
For ii = 1 To ColHead.Rows.Count- p5 ^/ h1 J% U2 O2 a
rngname = ColHead.Cells(ii, 1)
. w6 B$ l& g* H; M. p/ l/ |& gLE(ii) = InStr(rngname, "<=")
( G+ y' k# [8 M2 @# pIf LE(ii) > 0 Then, g$ c! M$ U% w4 K
rngname = Mid(rngname, 1, LE(ii) - 1)( ], y3 X' m, o* z1 G. U( |3 D' E
End If
$ t5 ]3 K( g4 A7 ?Values(ii) = Range(rngname)
- \& @& p* M4 U( T) J3 L( a'debug.Print "Variable:" & rngname & " is:" & Values(ii)" R, u) t `$ [4 d. o
PrevData(ii) = "" ' initialise
( ?$ n; r2 j1 j" TNext ii7 P% o3 H) l _1 Y- `, T1 ]

! y+ s c7 {6 mcindex = 25 N% g( G( \& L- {
'debug.Print ColHead.Columns.Count: f( q6 W+ J$ Y6 \. |
Match = False* T8 h6 H, [( U
For c = cindex To ColHead.Columns.Count; m. Y- h7 V/ P
For r = 1 To ColHead.Rows.Count ' for each dimension
; \; ~0 R3 C: V% S5 P3 Pdata = ColHead.Cells(r, c); M& ~% X6 F2 S5 C6 c% F
If data = "" Then
4 q* O3 g! n( q7 j'debug.Print "Empty cell found: using " & PrevData(r)
3 \/ X1 [ B0 C% e0 n# \; ^2 B' use the last valid cell on this row" s0 ^" U& I2 D* E" X6 c5 ]) B% N) q
' (this is to handle merged cells)
- E/ u7 K, t3 C2 e: C3 @! L0 Y: E4 Hdata = PrevData(r)
/ k' S. [" N* d. @End If3 t0 \: |( U z1 |
'debug.Print "data:" & data
3 `! G/ I4 X1 W0 m4 ?& }* u4 dPrevData(r) = data ' save for use by empty cellsj* c# I. T- b' p0 m
If data = Values(r) Or (data > Values(r) And LE(r) > 0) Or data = "*" Then/ m4 V$ r: A8 u# l! O, X
If r = ColHead.Rows.Count Then ' All rows match - It's a go
" d, O/ \2 |8 Z8 v$ fMatch = True$ U8 \7 N0 f) t
End If1 Y- J8 t1 W+ Z/ Y
Else ' This row doesn't match - go to the next column, v9 v$ h" K! c
Match = False' K$ G) `: {: O0 [* v8 N) a
Exit For: A& C+ N/ h- L( ?, p
End If6 o5 [3 ^0 X" a# F' J
Next r& }- R4 H' n. g9 `1 K3 i! O
If Match = True Then ' Don't search any more columns
" M4 o: T! Y4 e3 Acindex = c7 C; M4 j8 R1 S F( ]
Exit For
5 _, ], Y* k8 \$ O% k: q" lEnd If( ]2 @# T2 R8 B; u
Next c
: p. c; A l" H- c3 ~) @
6 _! c3 m" M! t; LIf Match = False Then ' Didn't find a matching set of values8 B t0 x. A I/ U
ZZL = "No match for columns"+ @+ d* D! z: m$ P
Exit Function
, F# u! f+ c8 h0 u: i7 uEnd If
6 ]) r* J- X B) }3 _& H$ @# t3 O# |4 P Z: ]
cindex = cindex + ColHead.Column - 1
" {- ~" }2 h. u5 ZEnd If" a, S2 S# I7 u" D

6 ]3 Z [0 S: p) ?6 t' Return the cell value from Table! B. W' A1 V7 f. [. G J5 k3 I
'debug.Print "Answer is in (R,C): " & rindex, cindex
, n! K2 i9 l7 p( s+ sZZL = ActiveSheet.Cells(rindex, cindex)
' \7 T/ K. h( p" E5 k3 s- S'debug.Print "Answer is : " & ZZL
: w* s# ^5 G& Z1 }Exit Function
H1 L$ o7 D* _3 d7 l: y- C. L
/ q7 L, T7 ?3 n3 Uerr_handler1:
0 d: P4 Y4 E2 i, VZZL = "Error on range '" & rngname & "'"
6 ~' Z: X5 W4 W0 H
' d. _& o9 L& c9 I ZEnd Function
0 y) @) {: X! D# i! ~3 n1 a
3 [) D1 z8 y4 c( M
2#
楼主 | 发表于 2022-6-6 18:04:26 | 只看该作者
本人是小白,想请教大佬,如何能看懂以上信息
3#
发表于 2022-6-6 19:17:09 | 只看该作者
微软官方的bbs里是有专业的VBA教程和API端口说明能检索的(全英文)
4#
发表于 2022-6-7 08:52:01 | 只看该作者
上excel必威APP精装版下载问问看
您需要登录后才可以回帖 登录| 注册会员

本版积分规则

小黑屋|手机版|Archiver|机械必威体育网址(京ICP备10217105号-1,京ICP证050210号,浙公网安备33038202004372号)

GMT+8, 2024-6-18 06:08, Processed in 0.050447 second(s), 14 queries , Gzip On.

Powered byDiscuz!X3.4Licensed

? 2001-2017Comsenz Inc.

快速回复 返回顶部 返回列表