ãã«ãã¦ã³ã§é¸æããã¨ãã·ã¼ãå ã®æå®ã»ã«ã«ã¸ã£ã³ãããã¤ãã³ãããã·ã¼ã¸ã£
ä»åã¯ããã«ãã¦ã³ã¡ãã¥ã¼ããé¸ãã æååã¨åãæååãå«ããåä¸ã·ã¼ãå ã®ã»ã«ã«ã¸ã£ã³ãããï¼ç»é¢ã®ä¸çªä¸ã«è¡¨ç¤ºãããï¼ã¤ãã³ãããã·ã¼ã¸ã£ãç´¹ä»ãã¾ãã
Â
ãã«ãã¦ã³ã¡ãã¥ã¼ããæååãé¸ã¶åº¦ã«ãåãæååãå«ãã»ã«ã
Â
ãã®ããã«ä¸çªä¸ã«è¡¨ç¤ºãããããã«ãããã¨æãã¾ãã
Â
VBAã§ã¯ãããæä½ãããªã¬ã¼ã¨ãã¦èªåçã«å®è¡ãããããã·ã¼ã¸ã£ããã¤ãã³ãããã·ã¼ã¸ã£ãã¨å¼ã³ã¾ããèªåå®è¡ã®ããªã¬ã¼ã¨ãªãæä½ã®ãã¨ããã¤ãã³ããã¨ãããä»åã¯ããã«ãã¦ã³ã¡ãã¥ã¼ï¼ãè¨ç½®ãããã»ã«ï¼ã®å 容ãå¤åããã度ã«ã
ã·ã¼ãå ã®æå®ç¯å²ãæ¤ç´¢ããæ¤ç´¢ã«ä¸è´ããã»ã«ãä¸çªä¸ã«è¡¨ç¤ºããã・・・・・・ã
ã¨ããããã°ã©ã ãèªåå®è¡ããã¦ã¿ããã¨æãã¾ãã
Â
ã¯ã¼ã¯ã·ã¼ãã®ã»ã«ãã¦ã¼ã¶ã¼ï¼ã¾ãã¯å¤é¨ãªã³ã¯ï¼ã«ãã£ã¦å¤æ´ãããã¨ãã«ãããã·ã¼ã¸ã£ãèªåçã«å®è¡ãããããã«ããã«ã¯ãWorksheet_Change ã¨ããã¤ãã³ãããã·ã¼ã¸ã£ã使ç¨ãã¾ãã
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myRange As Range
If Target.Address <> "$A$1" Then Exit Sub
Set myRange = Range("A2:A1048576").Find(Target.Value, LookAt:=xlWhole)
ActiveWindow.ScrollRow = myRange.Row
End Sub
Â
â»ããã°ã©ã ã®è§£èª¬
- Worksheet_Change ã¨ããååã®ã¤ãã³ãããã·ã¼ã¸ã£ãè¨è¿°ãã¾ããWorksheetã¨ãããªãã¸ã§ã¯ãã§ãChangeï¼å¤åï¼ã¨ããã¤ãã³ãããã£ãæã«èªåå®è¡ãããããã·ã¼ã¸ã£ã示ãã¾ããã¤ãã³ãããã·ã¼ã¸ã£åã¯ãã¦ã¼ã¶ã¼ãèªç±ã«å¤æ´ãããã¨ã¯ã§ãã¾ããã
- å¼æ°ã®æå®ã¯ã¤ãã³ãããã·ã¼ã¸ã£ãã¨ã«æ±ºã¾ã£ã¦ãããWorksheet_Change ã§ã¯(ByVal Target As Range)ã¨ãã¾ããã¯ã¼ã¯ã·ã¼ãå ã§å¤æ´ããã£ãã»ã«(Range)ã Target ã«æ ¼ç´ããã¾ããå¤æ°åã® Target ã¯ä»»æã§ãããå¼æ°ã®æ¸¡ãæ¹ãæå®ãã ByValï¼â»1ï¼ã¨ãå¤æ°ã®åãæå®ãã As Range ã¯å¤æ´ä¸å¯ã§ãã
- Ifã§ãå¤æ´ããã£ãã»ã«ã®ã¢ãã¬ã¹ã$A$1ï¼ã¤ã¾ãããã«ãã¦ã³ã¡ãã¥ã¼ãè¨ç½®ããã»ã«ï¼ä»¥å¤ã§ãã£ãå ´åã¯ãããã·ã¼ã¸ã£ãçµäºããä½ããã¾ããã
- Findã¡ã½ããã§ãA2:A1048576ï¼ã¤ã¾ããã¸ã£ã³ãå ã®è¦åºããåå¨ããã»ã«ç¯å²ï¼ãããã«ãã¦ã³ã¡ãã¥ã¼ã§é¸æããæååã§æ¤ç´¢ããä¸è´ããã»ã«(Range)ãè¿ãã¾ããLookAt:=xlWhole ã®å¼æ°ã§ãæ¤ç´¢æ¡ä»¶ãå®å ¨ä¸è´ã«ãã¦ãã¾ãã
- ActiveWindow.ScrollRowã§ãæ¤ç´¢ã«ä¸è´ããã»ã«ã®ããè¡ãä¸ç«¯ã«è¡¨ç¤ºããã¾ããã¦ã£ã³ãã¦æ ãåºå®ãã¦ããå ´åã åºå®é åã¯å¯¾è±¡å¤ã¨ãªãã¾ãã
â»ã³ã¼ãã®ä½¿ç¨æ¹æ³
- Private SubããEnd Subã¾ã§ãã³ãã¼ããã¤ãã³ããçºçãããªãã¸ã§ã¯ãã¢ã¸ã¥ã¼ã«ã«è²¼ãä»ãã¦ä½¿ç¨ãã¦ä¸ãããã¤ã¾ããbook1ã®Sheet1ã§çºçããã¤ãã³ãã«å¯¾ãã¦ã§ããã°ãVBAProject(Book1) ï¼ Microsoft Excel Objects ï¼ Sheet1 ã¢ã¸ã¥ã¼ã«ã«è¨è¿°ãã¾ããæ¨æºã¢ã¸ã¥ã¼ã«ããå人ç¨ãã¯ãããã¯ã«è¨è¿°ãã¦ãå®è¡ããã¾ããã
åæ§ã®å¦çããWorkbook_SheetChangeã¨ããã¤ãã³ãããã·ã¼ã¸ã£ã§ãä½æãããã¨ãã§ãã¾ãããã®å ´åã¯ãThisWorkbookã¢ã¸ã¥ã¼ã«ã«ã³ã¼ããè¨è¿°ãã¾ããWorkbook_SheetChangeã¯ãWorkbookã¨ãããªãã¸ã§ã¯ãï¼ã¤ã¾ããBookå ã®å ¨ã¦ã®ã·ã¼ãï¼ã§ãSheetChangeã¨ããã¤ãã³ãããã£ãæã«èªåå®è¡ãããããã·ã¼ã¸ã£ã§ããï¼Worksheet_Changeã¯ä¸ã¤ã®ã·ã¼ãã®ã¿ã対象ï¼
Â
â»1
ByValã¯ãå¼æ°ãå¤æ¸¡ãã«ãªãã¾ããåèã«ãçç¥ã¾ãã¯ByRefã¯ãå¼æ°ãåç
§æ¸¡ãã«ãªãã¾ããValã¯Valueï¼å¤ï¼ã®ç¥ã§ãRefã¯Referenceï¼åç
§ï¼ã®ç¥ã
å¤æ¸¡ãã¨åç
§æ¸¡ãã«ã¤ãã¦ã¯ãthom (id:t-hom) ããã®ãã¡ãã®è¨äºã§ãããããã解説ããã¦ãã¾ãã