è¤æ°ã®æåã®è²ã§ãã£ã«ã¿ãªã³ã°ãè¡ã
ã¨ã¯ã»ã«ã®ãªã¼ããã£ã«ã¿ã¼ã¯æåã®è²ã§ãã£ã«ã¿ã¼ãããããã¨ãã§ãã¾ãããè²ã¯ä¸ã¤ããæå®ã§ãã¾ãããã¾ããè¤æ°ã®ã»ã«ãé¸ãã§å³ã¯ãªãã¯ããããã£ã«ã¿ã¼ãâãé¸æããã»ã«ã®ãã©ã³ãè²ã§ãã£ã«ã¿ã¼ãããããã¨ãã¦ããè¤æ°ã®é¸æç¯å²ã«å¯¾ãã¦ã¯å®å¹ã§ããªãæ¨ã®è¦åã¡ãã»ã¼ã¸ãåºã¦ãã¾ãã¾ãã
VBAãªãã¨æã£ãã®ã§ãããç¨æããã¦ããã¡ã½ãããé¢æ°ã§ã¯ã§ããªãã¿ããã§ããï¼ãã¶ãï¼
ã¨ãããã¨ã§ãè¤æ°ã®æåã®è²ã§ãã£ã«ã¿ãªã³ã°ã§ããã³ã¼ããä½ã£ã¦ã¿ã¾ããã
ï¼ä»åã¯äºã¤ã®ã³ã¼ãã使ãã¾ãï¼
ã³ã¼ãï¼
Sub æåè²ã®å¤ãæ¹è¡åºåãã§ã¯ãªãããã¼ãã«æ ¼ç´() 'æ ¼ç´ããå¤ã¯ãªãã«ã¨ã³ãã£ã¢ã³ã§ã 'è¤æ°ã®æåè²ãæ··å¨ããã»ã«ã¯Nullã¨ãªãã¾ã Dim myRange As Range Dim V As String Dim myLib As Object Set myLib = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}") 'åç §è¨å®ãªãã§DataObjectã®ã¤ã³ã¹ã¿ã³ã¹ãçæãã If Selection.Count > 1 Then For Each myRange In Selection.SpecialCells(xlCellTypeVisible) 'å¯è¦ã»ã«ã®ã¿ã«å¦çãè¡ã If myRange.Address = myRange.MergeArea(1).Address Then 'çµåã»ã«ã®å ´åã¯å·¦ä¸ã®å¤ã®ã¿åãåºã V = V & myRange.Font.Color & vbCrLf End If Next myRange V = Left(V, Len(V) - 2) 'æçµè¡ã®æ¹è¡åºåããåãé¤ãï¼CrLfã¯2æåï¼ Else V = ActiveCell.Font.Color End If myLib.SetText V 'å¤æ°ã®å¤ãDataObjectã«æ ¼ç´ãã myLib.PutInClipboard 'DataObjectã®ãã¼ã¿ãã¯ãªãããã¼ãã«æ ¼ç´ãã End Sub
Â
ã³ã¼ãï¼
Sub è¤æ°ã®æåã®è²ã§çµè¾¼ã¿ãè¡ã() 'ã¯ãªãããã¼ãã«æ ¼ç´ãããæåè²ã®å¤ãåç §ããORæ¡ä»¶ã§çµè¾¼ã¿ãã¾ã 'å®è¡åã«çµãè¾¼ã¿ãè¡ãåç¯å²ï¼è¦åºããé¤ãï¼ãé¸æãã¦ããã¾ã 'æåè²ãä¸è´ããªãè¡ãé表示ã«ãã¾ãï¼ãªã¼ããã£ã«ã¿ã¼ã使ãã¾ããï¼ Dim V As Variant Dim i As Integer Dim x As Integer Dim y As Long Dim Yn As Long Dim myRange As Range Dim myLib As Object Set myLib = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}") 'åç §è¨å®ãªãã§DataObjectã®ã¤ã³ã¹ã¿ã³ã¹ãçæãã Application.ScreenUpdating = False 'ç»é¢è¡¨ç¤ºã®æ´æ°ããªãã«ãã myLib.GetFromClipboard On Error Resume Next V = myLib.GetText On Error GoTo 0 If Not IsEmpty(V) Then V = Split(CStr(V), vbCrLf) x = Selection.Column For y = Selection.Row To Selection.Rows(Selection.Rows.Count).Row i = 0 If Not IsNull(Cells(y, x).Font.Color) And Not Cells(y, x).Value = "" Then 'è¤æ°ã®æåè²ãæ··å¨ããã»ã«ï¼Nullï¼ã¨ç©ºç½ã®ã»ã«ï¼é»ã¨å¤ãéè¤ï¼ã¯ãæ¤ç´¢ã®å¯¾è±¡å¤ Do While i <= UBound(V) If CStr(Cells(y, x).Font.Color) = V(i) Then 'é åã®å 容ã¨ä¸è´ãã¦ããå ´åã¯è¡ãé²ãã Yn = y + 1 Do While Cells(y, x).Address = Cells(Yn, x).MergeArea(1).Address 'çµåã»ã«ãæããã¾ã§è¡ãé²ãã Yn = Yn + 1 Loop y = Yn - 1 GoTo nx Else i = i + 1 End If Loop End If If myRange Is Nothing Then Set myRange = Range(y & ":" & y) 'é åã®å å®¹å ¨ã¦ã¨ä¸è´ããªãã£ãä¸çªæåã®è¡ Else Set myRange = Union(myRange, Range(y & ":" & y)) 'é åã®å å®¹å ¨ã¦ã¨ä¸è´ããªãã£ãè¡ End If nx: Next y myRange.EntireRow.Hidden = True 'æ¤ç´¢ã«ä¸è´ããªãã£ãè¡ããã¹ã¦é表示ã«ãã Else MsgBox "ã¯ãªãããã¼ãã«ãã¼ã¿ãããã¾ããï¼" End If End Sub
â»ã³ã¼ãã®ä½¿ç¨æ¹æ³
SubããEnd Subã¾ã§ãã³ãã¼ããæ¨æºã¢ã¸ã¥ã¼ã«çã«è²¼ãä»ãã¦ä½¿ç¨ãã¦ä¸ããããªãããã¯ãã§å®è¡ããå¦çã¯ãå ã«æ»ãããã¨ãã§ãã¾ãããå®è¡åã«ä¸æ¦ä¿åãããç´ãã®ã§ããç¶æ ã«ãã¦ããã¦ä¸ãããæ¨æºã¢ã¸ã¥ã¼ã«ã«ã³ã¼ããè²¼ãä»ãã¦ãã¯ãã使ç¨ããæ¹æ³ã¯ãã¡ãã
Â
å®è¡æé
- ã¾ãããã£ã«ã¿ã¼ã«ä½¿ç¨ãããæåè²ã®ã»ã«ãè¤æ°é¸æããç¶æ ã§ãã³ã¼ãï¼ãå®è¡ãã¾ããï¼ãã®å¦çã§æåè²ã®å¤ãã¯ãªãããã¼ãã«ä¸æä¿åããã¾ãï¼
- ãã£ã«ã¿ãªã³ã°ãããåã®ç¯å²ãé¸æããã³ã¼ãï¼ãå®è¡ãã¾ãã
Â
å®è¡é¢¨æ¯ï¼äºåã«å®è¡æé ã®1.ã§èµ¤ã»éã»é»ã®æåè²ãåå¾æ¸ã¿ï¼
ãã£ã«ã¿ãªã³ã°è§£é¤ã¯ãæ¨æºæ©è½ã§è¡ãå表示ãã¦ãã¾ãã
Â
ããã°ã©ã ã®èª¬æ
âã³ã¼ãï¼
- é¸æãããã»ã«ããFont.Colorã§æåè²ã®å¤ãåå¾ããæ«å°¾ã«æ¹è¡ãä»ã足ãã¦å¤æ°ã«ä»£å ¥ãã
- é¸æããããã¹ã¦ã®ã»ã«ã«å¯¾ãã¦ãä¸è¨ãç¹°ãè¿ã
- æå¾ã«å¦çããã»ã«ã®æ¹è¡ãéªéãªã®ã§åãé¤ã
- å¤æ°ã®å 容ãã¯ãªãããã¼ãã«è»¢éãã
Â
âã³ã¼ãï¼
- ã¯ãªãããã¼ãã®ãã¼ã¿ãåãè¾¼ã¿ãSplité¢æ°ã§æ¹è¡ã¾ã§ãä¸ã¤ã®ãã¼ã¿ã¨ãã¦é åã«æ ¼ç´ãã
- ç¾å¨é¸æãã¦ããç¯å²ã®åçªå·ãåå¾ãã
- For Nextã®å§ã¾ãã®å¤ãé¸æç¯å²ã®ä¸ç«¯ã®è¡ãçµããã®å¤ãä¸ç«¯ã®è¡ããã
- ã¾ãã¯ä¸ç«¯ã®è¡ãããé åå ã®ãã¼ã¿ã¨ä¸è´ãããå¦ãæ¯è¼ãè¡ã
- é åå ã®ããããã®ãã¼ã¿ã¨ä¸è´ãã¦ããã°ãNext yã¸é£ã¶ï¼ä¸è´ããã»ã«ãçµåã»ã«ã®å ´åã¯ãçµåã»ã«ãæããã¾ã§è¡ãé²ããï¼
- é åå ã®ãã¼ã¿ãã¹ã¦ã¨ä¸è´ããªãã£ãå ´åã¯ããã®è¡ãUnionã¡ã½ããã§è¨æ¶ãã¦ãã
- ä¸ç«¯ã®è¡ã¾ã§ãFor ï½Nextã®ç¹°ãè¿ã
- æå¾ã«ãæ¤ç´¢ã«ä¸è´ããªãã£ãè¡ãã¾ã¨ãã¦é表示ã«ãã
- ã¾ããä¸ã®ããã«è¤æ°ã®æåè²ãæ··å¨ããã»ã«ã¯ãFont.Colorã®å¤ãNullã¨ãªãããæ¤ç´¢ã®å¯¾è±¡å¤ã¨ãããã¹ã¦é表示ã«ããã 空ç½ã®ã»ã«ã¯Font.Colorã®å¤ãé»ã®æåè²ã¨åãã«ãªãã®ã§ããããæ¤ç´¢ã®å¯¾è±¡å¤ã¨ãããã¹ã¦é表示ã«ããã
Â
課é¡
- äºã¤ã®ã³ã¼ãã使ãã®ã§ç ©éã
- ã¯ãªãããã¼ãã使ãæ¹æ³ã¯å®å®ããªãå ´åããããï¼ç§ã®ç°å¢ã ã¨ãã¯ãªãããã¼ãã¸ã®ã¢ã¯ã»ã¹ã«æ°ç¾åã«ä¸åº¦å¤±æãããã©ãããªã®ã§å®ç¨ä¸åé¡ãªãï¼
- ãã£ã«ã¿ãªã³ã°ç¯å²ãæåã§é¸æããã®ãé¢åãâ»èªåã§é¸æãããæ¹æ³ï¼CurrentRegionã使ãæ¹æ³ã»ã·ã¼ãã®æçµè¡ããEnd(xlUp)ããæ¹æ³ã»ç½«ç·ã®æç¡ã§å¤å®ããæ¹æ³ï¼ããããã©ã表ã®ä½ãæ¹ã¯äººã«ãã£ã¦åå·®ä¸å¥ãªã®ã§ç¢ºå®ã«èªåé¸æã§ããä¿è¨¼ããªã・・・・・・ã
- ãã£ã«ã¿ãªã³ã°ã®è§£é¤ãé¢åã