[µo°Ý]¦p¦ó¨Ï¥ÎVBA±N¦³«½Æ°Ñ·ÓȶK¨ì¤£¦Pworksheet
- ©«¤l
- 1
- ¥DÃD
- 1
- ºëµØ
- 0
- ¿n¤À
- 2
- ÂI¦W
- 0
- §@·~¨t²Î
- Win7
- ³nÅ骩¥»
- Win7
- ¾\ŪÅv
- 10
- µù¥U®É¶¡
- 2016-7-27
- ³Ì«áµn¿ý
- 2022-7-4
|
[µo°Ý]¦p¦ó¨Ï¥ÎVBA±N¦³«½Æ°Ñ·ÓȶK¨ì¤£¦Pworksheet
¦U¦ì±M®a¦n¡A§Ú¦Û¤vªñ´Á¶}©l¦Û¤vÆp¬ãµ{¦¡¼¶¼g,
¥Ñ©ó¬OVBA·s¤â¡Aªñ¨Ó°t¦X¤u§@©Ò»Ý·Qn¼g¤@ÓVBAµ{¦¡¡A¬d¤Fºô¸ô¤W³\¦h¸ê®Æ¡A¥²¶·¸ó¤£¦Pªí³æ°Ñ·Óªº¤@Ó§@·~
¥»·Q¨Ï¥Î¥¨¶°·f°tVlookup¨ç¼Æ¦ý¦]¬°¥L¨Ã¤£¬OCase sensitiveªº¨ç¼Æ¡A¦]¦¹§@½}
¹Á¸Õ¼g¤FIndex °Ñ·Óªí¦ýµo²{¤ñ¹ï·|°±¤£¤U¨Ó¡A§Ú·Q¸ò§Ú¤Uªº«ü¥O¦³Ãö
¹w´Á§Æ±æ«ö¤U«ö¶s(³z¹L"±a¤J¾¯à(right)"ªº«ö¶s,TriggerH2Äæ¦ìÅýªíA©³¤Uªº¯à±qªíBÄæ¦ìA¥H¤Î¨ä¬Û¦P¦C¸ê®Æ³£¯à¶×¤J¬Û¹ïÀ³ªºÈ
¦p¹Ï:
¦ý«÷´êªº¥¨¶°³£·|Åܦ¨³o¼Ë...
³o¬O§Úªºµ{¦¡½X- Sub «ö¶s9_Click()
- Dim SourceLastRow As Long
- Dim OutputLastRow As Long
- Dim sourceSheet As Worksheet
- Dim outputSheet As Worksheet
- 'What are the names of our worksheets?
- Set sourceSheet = Worksheets("competencylist_2016")
- Set outputSheet = Worksheets("inserttext")
- 'Determine last row of source
- With sourceSheet
- SourceLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
- End With
- With outputSheet
- 'Determine last row in col P
- OutputLastRow = .Cells(.Rows.Count, "P").End(xlUp).Row
- 'Apply our formula
-
-
- .Range("B6:B20" & OutputLastRow).Formula = _
- "=INDEX('competencylist_2016'!$C$2:$C$100, SMALL(INDEX(($H$2='competencylist_2016'!$A$2:$A$100)*(MATCH(ROW('competencylist_2016'!$A$2:$A$100),ROW('competencylist_2016'!$A$2:$A$100)))+($H$2<>'competencylist_2016'!$A$2:$A$100)*1048577,0,0),ROW('competencylist_2016'!A1)))"
- .Range("C6:C20" & OutputLastRow).Formula = _
- "=VLOOKUP(B:B,'" & sourceSheet.Name & "'!$C$1:$F$1" & SourceLastRow & ",2,0)"
- End With
- End Sub
½Æ»s¥N½X ±æ¦U¦ì¥ý¶iµ¹¤©«ü¾É¡AÁÂÁÂ!
VBA TEST08022016.rar (375.92 KB)
|
|
|
|
|
|
|
- ©«¤l
- 5923
- ¥DÃD
- 13
- ºëµØ
- 1
- ¿n¤À
- 5986
- ÂI¦W
- 0
- §@·~¨t²Î
- win10
- ³nÅ骩¥»
- Office 2010
- ¾\ŪÅv
- 150
- ©Ê§O
- ¨k
- ¨Ó¦Û
- ¥xÆW°ò¶©
- µù¥U®É¶¡
- 2010-5-1
- ³Ì«áµn¿ý
- 2022-1-23
|
¦^´_ 1# s5512765 - Range("B6:B20" & OutputLastRow).Formula
- .Range("C6:C20" & OutputLastRow).Formula =
½Æ»s¥N½X ¤u§@ªí¤W³]ªº¤½¦¡ ·í¾°È½s¸¹ ªºBBItem3,BItem4 ¤p©ó 20-6 ,©Ò®Mªº¤½¦¡, ·íµM¦³¿ù»~È
¸Õ¸Õ¬Ý- Option Explicit
- Sub «ö¶s9_Click()
- Dim sourceSheet As Worksheet '** Åܼƫ¬ºA¬°¤u§@ªíª«¥ó
- Dim outputSheet As Worksheet '** Åܼƫ¬ºA¬°¤u§@ªíª«¥ó
- 'What are the names of our worksheets?
- Set sourceSheet = Worksheets("competencylist_2016")
- Set outputSheet = Worksheets("inserttext")
- outputSheet.Range("B6:I" & Rows.Count) = "" '**²M°£Â¦³ªº¸ê®Æ
-
- With sourceSheet
- '**Count ÄÝ©Ê ¶Ç¦^¤@Ó Long (ªø¾ã¼Æ)¡Aµ¥©ó¦b¤@Ó¶°¦Xª«¥ó¤¤ªºª«¥ó¼Æ¥Ø¡C°ßŪ¡C
- '** Columns.Count -> ¤u§@ªíªº©Ò¦³Äæ¼Æ
-
- .Cells(1, Columns.Count - 3).Resize(, 4) = Array(.Range("A1"), "", .Range("C1"), .Range("D1"))
- '** ¼g¤J¦r¦ê BBItem1 ,"", BBItem3, BBItem4
-
- .Cells(2, Columns.Count - 3) = outputSheet.Range("H2") '**¾°È½s¸¹
-
- '**¶i¶¥¿z¿ï
- .Range("A1").CurrentRegion.AdvancedFilter xlFilterCopy, .Cells(1, Columns.Count - 3).Resize(2), .Cells(1, Columns.Count - 1).Resize(1, 2)
-
- '.Range("A1").CurrentRegion.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=.Cells(1, Columns.Count - 3).Resize(2), CopyToRange:=.Cells(1, Columns.Count - 1).Resize(1, 2)
- '** AdvancedFilter ½d³òªº¶i¶¥¿z¿ï , xlFilterCopy ¿z¿ï¨ì¨ä¥L¦ì¸m
- '**AdvancedFilter ¤èªk °ò©ó·Ç«h½d³ò±q¸ê®Æ²M³æ¤¤¿z¿ï©Î½Æ»s¸ê®Æ¡C¦pªGªì©l¿ï©w¬°³æÓÀx¦s®æ¡A«h¨Ï¥ÎÀx¦s®æ¥Ø«eªº°Ï°ìx¬°Variant¡C
- '** expression.AdvancedFilter(Action, CriteriaRange, CopyToRange, Unique)
- '**expression ¥²¿ï¡C¸Ó¹Bºâ¦¡·|¶Ç¦^ [®M¥Î©ó] ²M³æ¤¤ªº¨ä¤¤¤@Óª«¥ó¡C
- '** Action ¥²¿ïªº XlFilterAction ¸ê®ÆÃþ«¬¡C
- '** XlFilterAction ¥i¥H¬O³o¨Ç XlFilterAction ±`¼Æ¤§¤@¡C xlFilterCopyxlFilterInPlace
- '**CriteriaRange ¿ï¾Ü©Êªº Variant¡C·Ç«h½d³ò¡C¦pªG¬Ù²¤¦¹¤Þ¼Æ«hµL·Ç«h¡C
- '**CopyToRange ¿ï¾Ü©Êªº Variant¡C¦pªG Action ¬° xlFilterCopy¡A¦¹¤Þ¼Æ«ü©w³Q½Æ»s¦Cªº¥Ø¼Ð½d³ò¡C§_«h©¿²¤¦¹¤Þ¼Æ¡C
- '**Unique ¿ï¾Ü©Êªº Variant¡CY¬° True¡A«h¶È¿z¿ï°ß¤@ªº°O¿ý¡FY¬° False¡A«h¿z¿ï¥X©Ò¦³²Å¦X·Ç«hªº°O¿ý¡C¹w³]Ȭ° False¡C
-
- With .Cells(1, Columns.Count - 1).Resize(1, 2).CurrentRegion
- If .Rows.Count > 1 Then
- outputSheet.Range("B6").Resize(.Rows.Count - 1, 2) = .Rows("2:" & .Rows.Count).Value
- With outputSheet.Range("H6").Resize(.Rows.Count - 1, 2)
- .Columns(1) = "=RC[-2]-RC[-3]" '¤½¦¡ : ¥Î R1C1¬Û¹ï¦ì¸m
- .Columns(2) = "=RC[-2]-RC[-4]"
- End With
- End If
- End With
- .Cells(1, Columns.Count - 3).Resize(, 4).EntireColumn = "" '½d³ò: ²M°£¦r¦ê
- End With
- End Sub
½Æ»s¥N½X |
|
|
|
|
|
|