„Excel VBA“ susikerta
VBA sankirta naudojama norint gauti diapazono objektą, kuris yra dviejų ar daugiau diapazonų sankirta. Norint rasti susikertantį diapazono tašką, reikia pateikti mažiausiai du diapazonus. Visi kiti argumentai yra neprivalomi, atsižvelgiant į reikalavimą.
Žemiau pateikiama VBA INTERSECT formulės sintaksė.

- Arg1 kaip diapazonas: pirmasis susikertantis diapazonas.
- Arg2 kaip diapazonas: antrasis susikertantis diapazonas.
Žemiau pateiktuose pavyzdžiuose pamatysime keletą naudingų metodų.

Pavyzdžiai
1 pavyzdys
Pavyzdžiui, naudokite toliau pateiktus duomenis.

1 veiksmas: paskelbkite kintamąjį kaip variantą.
Kodas:
Sub Intersect_Example () Dim MyValue As Variant End Sub

2 žingsnis: Šiam kintamajam priskirkite vertę naudodami „Intersect“ formulę.
Kodas:
Sub Intersect_Pavyzdys () Dim MyValue As Variant MyValue = Intersect (End Sub

3 žingsnis: Pasirinkite pirmąjį diapazoną nuo B2 iki B9.
Kodas:
Sub Intersect_Example () Dim MyValue as Variant MyValue = Intersect (Range ("B2: B9"), End Sub

4 žingsnis: Pasirinkite antrą diapazoną nuo A5 iki D5.
Kodas:
Sub Intersect_Example () Dim MyValue as Variant MyValue = Intersect (Range ("B2: B9"), Range ("A5: D5") End Sub

5 žingsnis: čia bandome tik su dviem diapazonais. Uždarykite formulę ir pasirinkite metodą kaip VBA langelio adresą.
Kodas:
Sub Intersect_Example () Dim MyValue As Variant MyValue = Intersect (Range ("B2: B9"), Range ("A5: D5")). Adreso pabaiga Sub

6 žingsnis: parodykite vertę pranešimų laukelyje VBA.
Kodas:
Sub Intersect_Example () Dim MyValue As Variant MyValue = Intersect (Range ("B2: B9"), Range ("A5: D5")). Adresas MsgBox MyValue End Sub

Gerai, mes baigėme ir pamatysime, ką gausime pranešimų laukelyje.

Rezultatą gavome kaip B5, ty tiekiamo diapazono susikirtimo taško langelio adresą.
Panašiai, naudodami VBA INTERSECT metodą, galime padaryti daug daugiau dalykų.
2 pavyzdys
Pasirinkite sankirtos langelį
Norėdami pasirinkti tiekiamo diapazono sankirtos langelį, naudokite žemiau pateiktą kodą.
Kodas:
Sub Intersect_Example2 () Intersect (Range ("B2: B9"), Range ("A5: D5")). Pasirinkite End Sub
Tai pasirinks tiekiamo diapazono sankirtos langelį.

3 pavyzdys
Išvalyti susikirtimo langelio turinį : Norėdami išvalyti tiekiamo diapazono sankirtos langelio turinį, naudokite toliau pateiktą kodą.
Kodas:
Sub Intersect_Example2 () Intersect (Range ("B2: B9"), Range ("A5: D5")). ClearContents End Sub
4 pavyzdys
Keisti susikirtimo langelio langelio spalvos fono ir šrifto spalvą: Norėdami pakeisti sankirtos langelio fono spalvą ir sankirtos langelio vertės šrifto spalvą naudodami žemiau pateiktą kodą.
Kodas:
Sub Intersect_Example2 () Intersect (Range ("B2: B9"), Range ("A5: D5")). Cells.Interior.Color = rgbBlue Intersect (Range ("B2: B9"), Range ("A5: D5") Cells.Font.Color = rgbAliceBlue End Sub
Change the Value of the Intersection Cell: Using the Intersect function, we can also change the value of that cell into something else.

In the above data, the intersect value of the range “B2:B9” & “A5:D5” is cell B5 i.e., marked with blue color. Now by supplying this range to intersect function, we can actually change the value to something else.
The below code will change the value from 29398 to “New Value.”
Code:
Sub Intersect_Example3() Intersect(Range("B2:B9"), Range("A5:D5")).Value = "New Value" End Sub
Run the code above. We will get the word “New Value” in place of 29398.

Like this, by using the Intersect function, we can play around with the middle position value of the supplied range.
Things to Remember
- „Excel“ programoje, norėdami gauti diapazono sankirtos vertę, tarp dviejų diapazonų turime suteikti erdvės ženklą.
- Naudodami VBA kodavimą, mes galime paryškinti, suformatuoti, ištrinti ar pakeisti ir padaryti daug kitų dalykų iki sankryžos vertės.
- Jei kelios eilutės ir stulpeliai pateikiami susikirtimo funkcijai, gausime vidurines dvi reikšmes.