SpecialCells(xlCellTypeVisible)ã¡ã½ããã®ãã°ï¼ãåé¿ããï¼Tips-16ï¼
ä»åã¯ãå¯è¦ã»ã«ã®ã¿ãåå¾ããSpecialCells(xlCellTypeVisible)ã¡ã½ãã使ç¨æã®ãã°ã¨ããã¯ã®åé¿æ¹æ³ã«ã¤ãã¦èãã¦ã¿ããã¨æãã¾ãã
VBAçã§ã¯æåï¼ãªã®ãã©ããåããã¾ããããé表示ã®è¡ã¾ãã¯åãã·ã¼ãå ã«1以ä¸ããç¶æ ã§ãåä¸ã»ã«å¯¾ãã¦SpecialCells(xlCellTypeVisible)ã¡ã½ããã使ç¨ããã¨è¬ã®ãã°ãçºçããããã§ãã
ä¸ã®ã³ã¼ãã§è©¦ãã¦ã¿ããã¨æãã¾ããï¼åç´ã«ãé¸æãã¦ããå¯è¦ã»ã«ã«çµµæåãå ¥åããã ãã®ãã®ã§ãï¼
Sub test()
Dim myRange As Range
For Each myRange In Selection.SpecialCells(xlCellTypeVisible)
myRange.Value = "(ï¼ _ï¼ ;)"
DoEvents
Next myRange
End Sub
Â
ãã®ã³ã¼ããä¸ã®ã·ã¼ãã®B2ã»ã«ï¼åä¸ã»ã«ï¼ã§å®è¡ãã¦ã¿ã¾ããè²ä»ãã®è¡ããã³åã¯å®é¨ã§è¡¨ç¤ºâé表示ãåãæ¿ããäºå®ã®ç®æã§ãã
Â
ã¾ãããã°ãçºçããªãä¾ããã§ãã
é表示ã®è¡ã¾ãã¯åã1ã¤ããªãã·ã¼ãã§ãtestã³ã¼ããå®è¡ã
å¦çãB2ã»ã«ã®ã¿ã«è¡ããã¾ããï¼äºå®ã©ããã®çµæï¼
Â
以éããã°ãçºçããä¾ã§ãã
è¡çªå·5ãé表示ã«ãã¦ãtestã³ã¼ããå®è¡ã
å¦çãB2ã»ã«ã®ã¿ã§ã¯ãªããã·ã¼ãå ã®ãã¹ã¦ã®ã»ã«ã«è¡ãããå¿çãªãã«ãªãã¾ãã
Â
åçªå·Eãé表示ã«ããtestã³ã¼ããå®è¡ã
å¦çãB2ã»ã«ã®ã¿ã§ã¯ãªããEã®å·¦å´ãã¹ã¦ã«è¡ãããå¿çãªãã«ãªãã¾ãã
Â
è¡çªå·5ã¨åçªå·Eãé表示ã«ããtestã³ã¼ããå®è¡ã
å¦çãB2ã»ã«ã®ã¿ã§ã¯ãªãã5ã®ä¸å´ã¨Eã®å·¦å´ã®ãã¹ã¦ã«è¡ãããå¿çãªãã«ãªãã¾ãã
Â
ãªããé表示ã®æç¡ã«é¢ããã2以ä¸ã®ã»ã«ãé¸æããç¶æ ã§å®è¡ããã°ãä¸ã®ãããªãã°ã¯çºçãã¾ããã
Â
testã³ã¼ãã®ããã«ã¦ã¼ã¶ã¼ãç¯å²é¸æãã¦ããå®è¡ããã³ã¼ããããã£ããåä¸ã»ã«ã§å®è¡ãã¦ãã¾ãã¨åè¿°ã®ãã°ã«è¦èããã¾ãã
ãã¨ãã£ã¦ãã·ã¼ãå ã«é表示ãããããªãããã³ã¼ãå ã«SpecialCells(xlCellTypeVisible)ã¡ã½ããã使ããã¦ãããã©ãããã注æãããã®ããã§ã¦ã¼ã¶ã¼ãåä¸ã»ã«ã§ã®å®è¡å¯å¦ãå¤æããã®ã¯æ¬è³ªã®å®å ¨åã§ã¯ãªãã§ãããã
Â
ã¨ãããã¨ã§ãã¦ã¼ã¶ã¼ã«é ¼ããªããã°åé¿æ¹æ³ï¼æ«å®ï¼ãèãã¦ã¿ã¾ããtestã³ã¼ãã®å ´åã§ããã°ãä¸ã®èµ¤åç®æã追è¨ããã°ãã¦ã¼ã¶ã¼ãã¼ããããã¦ãã¦ãåé¿ã§ãã¾ãã
Sub testãã°åé¿ç()
Dim myRange As Range
If Selection.Count > 1 Then
For Each myRange In Selection.SpecialCells(xlCellTypeVisible)
myRange.Value = "(ï¼ _ï¼ ;)"
DoEvents
Next myRange
Else
ActiveCell.Value = "(ï¼ _ï¼ ;)"
End If
End Sub
ãã¤é¡ã§ããã»ã©ã®ãã¨ã§ã¯ãªãã§ããã
- é¸æç¯å²ãè¤æ°ã§ããã°ãSpecialCells(xlCellTypeVisible)ã¡ã½ããã使ãå¦ç
- é¸æç¯å²ãåä¸ã§ããã°ãSpecialCells(xlCellTypeVisible)ã¡ã½ããã使ããªãå¦ç
ã«åå²ããã¦ããã ãã§ãã
ãªã¼ããã£ã«ã¿ã§çµãè¾¼ãã§å°å·ï¼ãæ½åºæ¡ä»¶ã®åã ãç¹°ãè¿ãï¼
ä»åã¯ãªã¼ããã£ã«ã¿ã§çµãè¾¼ãã§ããå°å·ãããã¨ããä½æ¥ãèªååãã¦ã¿ããã¨æãã¾ãã
ãããªã¤ã¡ã¼ã¸ã
ãã®è¡¨ã®ååã®åã§ã
- "ãã¼ã·ã§ã³"ã§çµãè¾¼ã¿
- å°å·
- "éã®é"ã§çµãè¾¼ã¿
- å°å·
- "ãã§ããã¯ã¹ã®å°¾"ã§çµãè¾¼ã¿
- å°å·
- "ã¨ãªã¯ãµã¼"ã§çµãè¾¼ã¿
- å°å·
- çµäº
Â
ã¨ãããããªç¹°ãè¿ããèªååãã¾ãã
ãã£ããã³ã¼ããä½ã£ã¦ã¿ã¾ããã
Â
ã³ã¼ãï¼
Sub é¸æç¯å²ã®ãã¼ã¿ãæ¹è¡åºåãã§ã¯ãªãããã¼ãã«æ ¼ç´() 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.Value & vbCrLf End If Next myRange V = Left(V, Len(V) - 2) 'æçµè¡ã®æ¹è¡åºåããåãé¤ãï¼CrLfã¯2æåï¼ Else V = ActiveCell.Value End If myLib.SetText V 'å¤æ°ã®å¤ãDataObjectã«æ ¼ç´ãã myLib.PutInClipboard 'DataObjectã®ãã¼ã¿ãã¯ãªãããã¼ãã«æ ¼ç´ãã End Sub
Â
ã³ã¼ãï¼
Sub çµãè¾¼ãã§å°å·ãç¹°ãè¿ã() 'ã¯ãªãããã¼ãã®æååãé åã«åãè¾¼ã¿ãé åã®å 容ã§é çªã«çµè¾¼ã¿ãã¾ã 'ç¾å¨é¸æãã¦ããã»ã«ã®åããã£ã«ã¿ãªã³ã°ãã¾ã 'ã·ã¼ãã«ãªã¼ããã£ã«ã¿ã¼ããªãå ´åã¯ããã®ã»ã«ãå«ãã¢ã¯ãã£ãã»ã«é åããªã¼ããã£ã«ã¿ã¼ã«è¨å®ããä¸ã§çµè¾¼ã¿ãã¾ã 'ç¾å¨ã®å°å·è¨å®ã§å°å·ãã¾ã Dim XS As Integer Dim XP As Integer Dim YS As Long Dim YE As Long Dim V As Variant Dim i As Integer Dim å¯è¦ã»ã«æ° As Long Dim myLib As Object Set myLib = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}") 'åç §è¨å®ãªãã§DataObjectã®ã¤ã³ã¹ã¿ã³ã¹ãçæãã myLib.GetFromClipboard On Error Resume Next V = myLib.GetText On Error GoTo 0 If Not IsEmpty(V) Then V = Split(CStr(V), vbCrLf) ActiveCell.AutoFilter Field:=1 'å¼æ°ã¯æ¢ã«ãªã¼ããã£ã«ã¿ã¼ãããå ´åã«è§£é¤ããªãããã®ããã¼ XP = ActiveCell.Column 'ç¾å¨é¸æãã¦ããã»ã«ã®åçªå·ãåå¾ XS = ActiveCell.Worksheet.AutoFilter.Range.Column 'ãªã¼ããã£ã«ã¿ã¼ãé©ç¨ãããç¯å²ã®å·¦ç«¯ã®åçªå·ãåå¾ XP = XP + 1 - XS 'æ½åºæ¡ä»¶ã®å¯¾è±¡ã¨ãªãåçªå· YS = ActiveCell.Worksheet.AutoFilter.Range.Row 'ãªã¼ããã£ã«ã¿ã¼ãé©ç¨ãããç¯å²ã®ä¸ç«¯ã®è¡çªå·ãåå¾ YE = ActiveCell.Worksheet.AutoFilter.Range.Rows(ActiveCell.Worksheet.AutoFilter.Range.Rows.Count).Row 'ãªã¼ããã£ã«ã¿ã¼ãé©ç¨ãããç¯å²ã®ä¸ç«¯ã®è¡çªå·ãåå¾ i = 0 Do While i <= UBound(V) ActiveCell.AutoFilter Field:=XP, Criteria1:=V(i), Operator:=xlFilterValues å¯è¦ã»ã«æ° = Range(Cells(YS, XP), Cells(YE, XP)).Columns(1).SpecialCells(xlCellTypeVisible).Cells.Count If å¯è¦ã»ã«æ° > 1 Then ActiveSheet.PrintOut: DoEvents 'çµãè¾¼ã¿ã«ä¸è´ãããã®ããã£ãå ´åã®ã¿å°å·ãã i = i + 1 Loop Else MsgBox "ã¯ãªãããã¼ãã«ãã¼ã¿ãããã¾ããï¼" End If End Sub
â»ã³ã¼ãã®ä½¿ç¨æ¹æ³
SubããEnd Subã¾ã§ãã³ãã¼ããæ¨æºã¢ã¸ã¥ã¼ã«çã«è²¼ãä»ãã¦ä½¿ç¨ãã¦ä¸ããããªãããã¯ãã§å®è¡ããå¦çã¯ãå ã«æ»ãããã¨ãã§ãã¾ãããå®è¡åã«ä¸æ¦ä¿åãããç´ãã®ã§ããç¶æ ã«ãã¦ããã¦ä¸ãããæ¨æºã¢ã¸ã¥ã¼ã«ã«ã³ã¼ããè²¼ãä»ãã¦ãã¯ãã使ç¨ããæ¹æ³ã¯ãã¡ãã
Â
å®è¡æé
- ã¾ããæ½åºæ¡ä»¶ã«ãããæååãå ¥ã£ãã»ã«ãè¤æ°é¸æããç¶æ ã§ãã³ã¼ãï¼ãå®è¡ãã¾ããï¼ãã®å¦çã§åæååãã¯ãªãããã¼ãã«ä¸æä¿åããã¾ããæ¢ã«åæååãæ¹è¡ã§åºåãããç¶æ ã§ã¯ãªãããã¼ãã«å ¥ã£ã¦ããã°ããã®æé ã¯çç¥ã§ãã¾ããä¾ãã°ããã©ã¦ã¶ãã¨ãã£ã¿çã ããã®ã³ãã¼ã§ãå¯ï¼
- çµãè¾¼ã¿ãããåã®ã©ãã§ãããã®ã§é¸æããã³ã¼ãï¼ãå®è¡ãã¾ãã
Â
å®è¡é¢¨æ¯ï¼æé ï¼ã¯çç¥ï¼
- â»å®éã¯ãã£ã¨é«éã§ããç®ã§è¦ããããã«ã¹ãããå®è¡ãã¦ãã¾ãã
Â
ããã°ã©ã ã®èª¬æ
âã³ã¼ãï¼
- é¸æãããã»ã«ããæååãåå¾ããæ«å°¾ã«æ¹è¡ãä»ã足ãã¦å¤æ°ã«ä»£å ¥ãã
- é¸æããããã¹ã¦ã®ã»ã«ã«å¯¾ãã¦ãä¸è¨ãç¹°ãè¿ã
- æå¾ã«å¦çããã»ã«ã®æ¹è¡ãéªéãªã®ã§åãé¤ã
- å¤æ°ã®å 容ãã¯ãªãããã¼ãã«è»¢éãã
âã³ã¼ãï¼
- ã¯ãªãããã¼ãã®ãã¼ã¿ãåãè¾¼ã¿ãSplité¢æ°ã§æ¹è¡ã¾ã§ãä¸ã¤ã®ãã¼ã¿ã¨ãã¦é åã«æ ¼ç´ãã
- ã·ã¼ãã«ãªã¼ããã£ã«ã¿ã¼ããªãå ´åã¯ãç¾å¨é¸æä¸ã®ã»ã«ãå«ãã¢ã¯ãã£ãã»ã«é åããªã¼ããã£ã«ã¿ã¼ã«è¨å®
- ãªã¼ããã£ã«ã¿ã¼ãé©ç¨ãããç¯å²ã®å·¦ç«¯ãåå¾
- ç¾å¨é¸æä¸ã®ã»ã«ããªã¼ããã£ã«ã¿ã¼ç¯å²ã®å·¦ç«¯ããä½åç®ããåå¾
- ãªã¼ããã£ã«ã¿ã¼ãé©ç¨ãããç¯å²ã®ä¸ç«¯ãä¸ç«¯ãããããåå¾ï¼çµãè¾¼ã¿çµæããç¡ããã ã£ãå ´åã®å¤å®ç¨ã«ï¼
- Do While ï½Loopã§ã以ä¸ã®å¦çãé åã®å ¨è¦ç´ ã«ã¤ãã¦å®æ½ãã
- ãªã¼ããã£ã«ã¿ã¼ã§çµãè¾¼ã¿ãè¡ãï¼æ½åºæ¡ä»¶ã¯é åã®å¤ï¼
- ãªã¼ããã£ã«ã¿ã¼ãé©ç¨ãããç¯å²ã®ä¸ç«¯ããä¸ç«¯ã¾ã§ã®ç¸¦æ¹åã®å¯è¦ã»ã«æ°ãã«ã¦ã³ããã
- å¯è¦ã»ã«æ°ã1ãè¶ ãã¦ããã°ãçµãè¾¼ã¿çµæãæããã¨ãã¦ãç¾å¨ã®å°å·è¨å®ã§å°å·ãè¡ãã1以ä¸ã§ããã°çµãè¾¼ã¿çµæããç¡ããã®ããå°å·ããªãï¼ä¸ã®ããã«è¦åºãã®ã¿å¯è¦ã»ã«ã¨ãªãï¼ã
Â
å°å·ãæ°ç¾åç¹°ãè¿ããããªå ´åã¯ãã¯ãå®è¡å¾ãçµããã¾ã§ã³ã¼ãã¼ã§ã飲ãã§ããããå¥ã®ä»äºã§ããã¦ããã®ãåã§ãããã ããããªã³ã¿å´ã®ç¨ç´åãã»ããã¼åãã»ç¨ç´è©°ã¾ããªã©ã®ç°å¸¸ãVBAå´ã§æ¤ç¥ããè¡ããªãã®ã§ï¼APIã§ãã§ããªãã¯ã・・・・・・ï¼è¦æ³¨æãVBAã¯ããªã³ã¿ãæ»ãã§ãã¦ãã¬ããªã³ã°ã¬ã³ã®ããã«å°å·æ令ãæã¡ç¶ãã¾ãã
æå®æååã®å·¦å´ã¾ãã¯å³å´ãåãåºã
ä»åã¯æå®æååã®å·¦å´ã¾ãã¯å³å´ãåãåºãã³ã¼ããèãã¦ã¿ããã¨æãã¾ããä¾ãã°ãæ°åãããã¹ãã¼ã¹ãå¢ã«ãã¦å§ã¨åãåãåºããã・・・・・・ãã¨ãã
ãã ããããªã®ã¯æ¢ã«ä¸ã®ä¸ã«ããæ°ãããã®ã§ãããããåæ©é²ãã å¦çãèãã¦ã¿ããã¨æãã¾ãã
Â
å¢ã«ãããæå®æååãã»ã«å ã«è¤æ°ããå ´åãå·¦ããä½åç®ããæå®ã§ããããã«ããã
ãããªæãã
å·¦ããï¼åç®ã®å ¨è§ã¹ã©ãã·ã¥ãå¢ã«ãã¦ãå·¦å´ã¾ãã¯å³å´ãåãåºãããã
Â
å·¦å´ãåãåºããçµæ
Â
å³å´ãåãåºããçµæ
Â
ã¨ãããã¨ã§ãã³ã¼ããä½ã£ã¦ã¿ã¾ãããï¼ã¤ãã§ã«ãæå®æååãå«ãã§åãåºããã©ãããé¸æã§ããããã«ããï¼
å·¦å´ãåãåºãã³ã¼ã
Sub æå®æåã®å·¦å´ãåãåºã() 'é¸æç¯å²ã«å¯¾ãã¦å¦çãè¡ãã¾ã Dim æå®æå As String Dim å¢ As Integer Dim tmp As Integer Dim å« As Integer Dim myRange As Range Dim å§ As Integer Dim i As Integer Dim ä½ç½® As Integer æå®æå = InputBox("æå®æåãå ¥åãã¦ä¸ããã") If æå®æå = "" Then Exit Sub å¢ = InputBox("å·¦ããä½åç®ã®æå®æåãå¢ã«ãã¾ããï¼") tmp = MsgBox("æå®æåãå«ãã§åãåºãã¾ããï¼", vbYesNoCancel) If tmp = vbYes Then å« = Len(æå®æå) ElseIf tmp = vbNo Then å« = 0 Else Exit Sub End If For Each myRange In Selection å§ = 1 'æ¤ç´¢éå§ä½ç½® For i = 2 To å¢ 'å·¦ãã2åç®ä»¥éã®æå®æåãå¢ã«ããå ´åã®æ¤ç´¢éå§ä½ç½®ãæ±ãã If InStr(å§, myRange.Value, æå®æå) > 0 Then å§ = InStr(å§, myRange.Value, æå®æå) + Len(æå®æå) Else Exit For End If Next i ä½ç½® = InStr(å§, myRange.Value, æå®æå) If ä½ç½® > 0 Then myRange.Value = Left(myRange.Value, ä½ç½® + å« - 1) End If Next myRange End Sub
Â
å³å´ãåãåºãã³ã¼ã
Sub æå®æåã®å³å´ãåãåºã() 'é¸æç¯å²ã«å¯¾ãã¦å¦çãè¡ãã¾ã Dim æå®æå As String Dim å¢ As Integer Dim tmp As Integer Dim å« As Integer Dim myRange As Range Dim å§ As Integer Dim i As Integer Dim ä½ç½® As Integer æå®æå = InputBox("æå®æåãå ¥åãã¦ä¸ããã") If æå®æå = "" Then Exit Sub å¢ = InputBox("å·¦ããä½åç®ã®æå®æåãå¢ã«ãã¾ããï¼") tmp = MsgBox("æå®æåãå«ãã§åãåºãã¾ããï¼", vbYesNoCancel) If tmp = vbYes Then å« = 0 ElseIf tmp = vbNo Then å« = Len(æå®æå) Else Exit Sub End If For Each myRange In Selection å§ = 1 'æ¤ç´¢éå§ä½ç½® For i = 2 To å¢ 'å·¦ãã2åç®ä»¥éã®æå®æåãå¢ã«ããå ´åã®æ¤ç´¢éå§ä½ç½®ãæ±ãã If InStr(å§, myRange.Value, æå®æå) > 0 Then å§ = InStr(å§, myRange.Value, æå®æå) + Len(æå®æå) Else Exit For End If Next i ä½ç½® = InStr(å§, myRange.Value, æå®æå) If ä½ç½® > 0 Then myRange.Value = Right(myRange.Value, Len(myRange.Value) - ä½ç½® - å« + 1) End If Next myRange End Sub
â»ã³ã¼ãã®ä½¿ç¨æ¹æ³
SubããEnd Subã¾ã§ãã³ãã¼ããæ¨æºã¢ã¸ã¥ã¼ã«çã«è²¼ãä»ãã¦ä½¿ç¨ãã¦ä¸ããããªãããã¯ãã§å®è¡ããå¦çã¯ãå ã«æ»ãããã¨ãã§ãã¾ãããå®è¡åã«ä¸æ¦ä¿åãããç´ãã®ã§ããç¶æ ã«ãã¦ããã¦ä¸ãããæ¨æºã¢ã¸ã¥ã¼ã«ã«ã³ã¼ããè²¼ãä»ãã¦ãã¯ãã使ç¨ããæ¹æ³ã¯ãã¡ãã
Â
å®è¡æé
- å¦çãããç¯å²ãé¸æãã¦ãã¯ããå®è¡ããã
- InputBoxã表示ãããã®ã§ãæå®æååãå ¥åãããï¼å¿ ãããã1æåã§ããå¿ è¦ã¯ç¡ãï¼
- å¼ãç¶ãInputBoxã表示ãããã®ã§ãå·¦ããä½åç®ã®æå®æååãå¢ã«ããããå ¥åããã
- æå®æååãå«ãã§åãåºããã©ãããããã¯ãããããããã§é¸æããã
Â
ããã°ã©ã ã®èª¬æ
- InputBoxããã³MsgBoxã§å¦çã«å¿ è¦ãªæ å ±ã®å ¥åãä¿ãã
- For Each ï½Nextã§é¸æç¯å²ã«å¯¾ãã¦é çªã«å¦çãè¡ãã
- æååæ¤ç´¢éå§ä½ç½®ã®åæå¤ã1æåç®ã¨ããã
- For ï½Nextã®å¦çãå¢ã¨ããæååãå·¦ãã2åç®ä»¥éã¨ããå ´åã®ãæååæ¤ç´¢éå§ä½ç½®ãæ±ãããï¼å·¦ãã1æåç®ã¨ããå ´åããã®ã«ã¼ãã«ã¯å ¥ããªãï¼
- InStré¢æ°ã§ãæå®æååï¼nåç®ï¼ã®ä½ç½®ãæ±ããã
- å·¦å´ããï¼ã¾ãã¯å³å´ããï¼æå®æååã®æåã¾ã§ãåãåºããâ»æå®æååãå«ãããã¯ããã«ããå ´åã¯ãå«ãã§åãåºãã
Â
ä½è«ã§ãããExcel 2013以éã§ããã°ãã©ãã·ã¥ãã£ã«ã§ä¼¼ããããªãã¨ãã§ãã¾ããï¼ãã ããã©ãã·ã¥ãã£ã«ã§ã¯æã£ãéãã®çµæã«ãªããªããã¨ããã£ããããï¼
Â
Â
追è¨
ãã¨ãã¡ã ãããã®ã³ã¡ã³ãã«ããããã«ãSplité¢æ°ã®ç¬¬ä¸å¼æ° Limitãæ´»ç¨ããã³ã¼ããä½ã£ã¦ã¿ã¾ãããå ã®ã³ã¼ãã¯æ¥µåãã®ã¾ã¾ã§Splité¢æ°ã«ç½®ãæãã¦ãã¾ããå³å´ãåãåºãã³ã¼ãã«é¢ãã¦ã¯ããªãã¹ãããªãã¾ããã
å³å´ãåãåºãã³ã¼ãï¼å ã³ã¼ãã¨ã®éãã赤ã«ãã¦ãã¾ãï¼
Sub æå®æåã®å³å´ãåãåºãlimitç()
'é¸æç¯å²ã«å¯¾ãã¦å¦çãè¡ãã¾ã
Dim æå®æå As String
Dim å¢ As Integer
Dim tmp As Integer
Dim å« As String
Dim myRange As Range
Dim é
å As Variant
æå®æå = InputBox("æå®æåãå
¥åãã¦ä¸ããã")
If æå®æå = "" Then Exit Sub
å¢ = InputBox("å·¦ããä½åç®ã®æå®æåãå¢ã«ãã¾ããï¼")
tmp = MsgBox("æå®æåãå«ãã§åãåºãã¾ããï¼", vbYesNoCancel)
If tmp = vbYes Then
å« = æå®æå
ElseIf tmp = vbNo Then
å« = ""
Else
Exit Sub
End If
For Each myRange In Selection
é
å = Split(myRange.Value, æå®æå, å¢ + 1)
myRange.Value = å« & é
å(UBound(é
å))
Next myRange
End Sub
Â
å·¦å´ãåãåºãã³ã¼ãï¼ä¸è¨ãå³å´ãåãåºãã³ã¼ãã¨ã®éããç´«ã«ãã¦ãã¾ãï¼Â
Sub æå®æåã®å·¦å´ãåãåºãlimitç()
'é¸æç¯å²ã«å¯¾ãã¦å¦çãè¡ãã¾ã
Dim æå®æå As String
Dim å¢ As Integer
Dim tmp As Integer
Dim å« As String
Dim myRange As Range
Dim ç·æ° As Integer
Dim é
å As Variant
æå®æå = InputBox("æå®æåãå
¥åãã¦ä¸ããã")
If æå®æå = "" Then Exit Sub
å¢ = InputBox("å·¦ããä½åç®ã®æå®æåãå¢ã«ãã¾ããï¼")
tmp = MsgBox("æå®æåãå«ãã§åãåºãã¾ããï¼", vbYesNoCancel)
If tmp = vbYes Then
å« = æå®æå
ElseIf tmp = vbNo Then
å« = ""
Else
Exit Sub
End If
For Each myRange In Selection
ç·æ° = (Len(myRange.Value) - Len(Replace(myRange.Value, æå®æå, ""))) / Len(æå®æå) 'ã»ã«å
ã®æå®æåã®ç·æ°ãæ±ãã
é
å = Split(StrReverse(myRange.Value), StrReverse(æå®æå), ç·æ° - å¢ + 2)
myRange.Value = StrReverse(é
å(UBound(é
å))) & å«
Next myRange
End Sub
Â
ããè¡ã®é«ããåå¹ ããä»ã®è¡ã¾ãã¯åã«é©ç¨ãã
ã¨ã¯ã»ã«ã使ç¨ãã¦ããã¨ãè¡ã®é«ããåã®å¹
ãã³ãã¼ãã¦ä»ã®è¡ã»åã«é©ç¨ãããã¨ããããã¾ãã
ãããªã¨ãã¯ã©ãããã°ããã§ããããï¼
 ç®æ¬¡
- å½¢å¼ãé¸æãã¦è²¼ãä»ãããæ¹æ³
- é«ããå¹ ã確èªãã¦ãããä»ã®è¡ã»åã«è¨å®ããæ¹æ³
- ãã¯ãã§é©ç¨ããæ¹æ³
Â
å½¢å¼ãé¸æãã¦è²¼ãä»ãããæ¹æ³
æ°å¼ãæ¸å¼ã®ã¿ãã³ãã¼ãã¦è²¼ãä»ãã§ããã®ã¨åãããã«ãåå¹ ã®ã¿ãã³ãã¼ãã¦è²¼ãä»ãããã¨ãã§ãã¾ãã
Â
・・・・・・ããï¼è¡é«ãã¯ï¼
ãªãããå½¢å¼ãé¸æãã¦è²¼ãä»ãããæ¹æ³ã«ã¯è¡é«ãã®ã¿ãã³ããããæ©è½ãããã¾ããã
Â
é«ããå¹ ã確èªãã¦ãããä»ã®è¡ã»åã«è¨å®ããæ¹æ³
ãããä¸çªåå§çãªæ¹æ³ã§ãããææ¬ã«ãããè¡ãåã®å¢ç®ãããï¼ã«ã¼ã½ã«ã®å½¢ãå¤ããæï¼ã§ã¯ãªãã¯ãã¦ãå¤ã確èªã
Â
次ã«ãå¤ãåãã«ãããè¡ã¾ãã¯åãé¸æããç¶æ ã§å³ã¯ãªãã¯âãè¡ã®é«ãï¼ã¾ãã¯åã®å¹ ï¼ãã§åãå¤ãå ¥åãã¦OKãã¾ãã
Â
ãã ããå¤ã確èªããå ¥åããæéãããã¾ãã
Â
ãã¯ãã§é©ç¨ããæ¹æ³
ä¸ã®æ¹æ³ã§ãååãªã®ã§ãããã¡ãã£ã¨ã ãï¼ã»ãã®ã¡ãã£ã¨ã ãï¼ç°¡åã«ã§ãããã¯ããä½ã£ã¦ã¿ã¾ããã
Sub è¡ã®é«ããåå¹ ãä»ã®è¡ã¾ãã¯åã«é©ç¨ãã() 'é©ç¨å ã®è¡å ¨ä½ã¾ãã¯åå ¨ä½ãé¸æããç¶æ ã§å®è¡ãã 'ã¤ã³ãããããã¯ã¹ã§é©ç¨å ã®è¡ã¾ãã¯åãæå®ãã Dim åçªå· As String Dim åå¹ As Double Dim è¡çªå· As Long Dim è¡é«ã As Double If Selection.Address = Selection.EntireColumn.Address Then åçªå· = InputBox("åå¹ ã®é©ç¨å ã¨ãªãåçªå·ãã¢ã«ãã¡ãããã§æå®") åçªå· = StrConv(åçªå·, vbNarrow) If åçªå· Like "*[!A-Za-z]*" Then GoTo ã¨ã©ã¼å¦ç On Error GoTo ã¨ã©ã¼å¦ç åå¹ = Columns(åçªå·).ColumnWidth On Error GoTo 0 Selection.ColumnWidth = åå¹ ElseIf Selection.Address = Selection.EntireRow.Address Then è¡çªå· = InputBox("è¡é«ãã®é©ç¨å ã¨ãªãè¡çªå·ãæå®") On Error GoTo ã¨ã©ã¼å¦ç è¡é«ã = Rows(è¡çªå·).RowHeight On Error GoTo 0 Selection.RowHeight = è¡é«ã End If Exit Sub ã¨ã©ã¼å¦ç: MsgBox "åå¨ããªãè¡ã¾ãã¯åã§ãã" End Sub
â»ã³ã¼ãã®ä½¿ç¨æ¹æ³
SubããEnd Subã¾ã§ãã³ãã¼ããæ¨æºã¢ã¸ã¥ã¼ã«çã«è²¼ãä»ãã¦ä½¿ç¨ãã¦ä¸ããããªãããã¯ãã§å®è¡ããå¦çã¯ãå ã«æ»ãããã¨ãã§ãã¾ãããå®è¡åã«ä¸æ¦ä¿åãããç´ãã®ã§ããç¶æ ã«ãã¦ããã¦ä¸ãããæ¨æºã¢ã¸ã¥ã¼ã«ã«ã³ã¼ããè²¼ãä»ãã¦ãã¯ãã使ç¨ããæ¹æ³ã¯ãã¡ãã
Â
å®è¡æé
- é«ããå¹ ãå¤æ´ãããè¡ã¾ãã¯åãé¸æããç¶æ ã§ãã¯ããå®è¡ã
- InputBoxã表示ãããã®ã§ããææ¬ã«ãããè¡ã¾ãã¯åãå ¥åãã¦OKãããâ»è¡ã¯æ°åãåã¯ã¢ã«ãã¡ãããã§å ¥åããã
Â
・・・・・・ããã¾ã§æ¸ãã¦ã¢ã¬ã§ããããã¯ããç¨æããã»ã©ã§ããªãã£ãããã
è¤æ°ã®ã»ã«ã®è²ã§ãã£ã«ã¿ãªã³ã°ãè¡ã
ååã¯è¤æ°ã®æåã®è²ã§ããããä»åã¯è¤æ°ã®ã»ã«ã®è²ã§ãã£ã«ã¿ãªã³ã°ãã¦ã¿ã¾ããããå 容ã¯ä¸é¨ãååã¨éè¤ãã¾ãã®ã§ãäºæ¿ãã ããã
ã¨ã¯ã»ã«ã®ãªã¼ããã£ã«ã¿ã¼ã¯ã»ã«ã®è²ã§ãã£ã«ã¿ã¼ãããããã¨ãã§ãã¾ãããè²ã¯ä¸ã¤ããæå®ã§ãã¾ãããã¾ããè¤æ°ã®ã»ã«ãé¸ãã§å³ã¯ãªãã¯ããããã£ã«ã¿ã¼ãâãé¸æããã»ã«ã®è²ã§ãã£ã«ã¿ã¼ãããããã¨ãã¦ããè¤æ°ã®é¸æç¯å²ã«å¯¾ãã¦ã¯å®å¹ã§ããªãæ¨ã®è¦åã¡ãã»ã¼ã¸ãåºã¦ãã¾ãã¾ãã
VBAãªãã¨æã£ãã®ã§ãããç¨æããã¦ããã¡ã½ãããé¢æ°ã§ã¯ã§ããªãã¿ããã§ããï¼ãã¶ãï¼
Â
ã¨ãããã¨ã§ãè¤æ°ã®ã»ã«ã®è²ã§ãã£ã«ã¿ãªã³ã°ã§ããã³ã¼ããä½ã£ã¦ã¿ã¾ããã
ï¼ä»åã¯äºã¤ã®ã³ã¼ãã使ãã¾ãï¼
ã³ã¼ãï¼
Sub ã»ã«è²ã®å¤ãæ¹è¡åºåãã§ã¯ãªãããã¼ãã«æ ¼ç´() 'æ ¼ç´ããå¤ã¯ãªãã«ã¨ã³ãã£ã¢ã³ã§ã 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.Interior.Color & vbCrLf End If Next myRange V = Left(V, Len(V) - 2) 'æçµè¡ã®æ¹è¡åºåããåãé¤ãï¼CrLfã¯2æåï¼ Else V = ActiveCell.Interior.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 Do While i <= UBound(V) If CStr(Cells(y, x).Interior.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 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.ã§èµ¤ã»éã»é»ã®ã»ã«è²ãåå¾æ¸ã¿ï¼
ãã£ã«ã¿ãªã³ã°è§£é¤ã¯ãæ¨æºæ©è½ã§è¡ãå表示ãã¦ãã¾ãã
Â
ããã°ã©ã ã®èª¬æ
- å²æ
Â
課é¡
- äºã¤ã®ã³ã¼ãã使ãã®ã§ç ©éã
- ã¯ãªãããã¼ãã使ãæ¹æ³ã¯å®å®ããªãå ´åããããï¼ç§ã®ç°å¢ã ã¨ãã¯ãªãããã¼ãã¸ã®ã¢ã¯ã»ã¹ã«æ°ç¾åã«ä¸åº¦å¤±æãããã©ãããªã®ã§å®ç¨ä¸åé¡ãªãï¼
- ãã£ã«ã¿ãªã³ã°ç¯å²ãæåã§é¸æããã®ãé¢åãâ»èªåã§é¸æãããæ¹æ³ï¼CurrentRegionã使ãæ¹æ³ã»ã·ã¼ãã®æçµè¡ããEnd(xlUp)ããæ¹æ³ã»ç½«ç·ã®æç¡ã§å¤å®ããæ¹æ³ï¼ããããã©ã表ã®ä½ãæ¹ã¯äººã«ãã£ã¦åå·®ä¸å¥ãªã®ã§ç¢ºå®ã«èªåé¸æã§ããä¿è¨¼ããªã・・・・・・ã
- ãã£ã«ã¿ãªã³ã°ã®è§£é¤ãé¢åã
è¤æ°ã®æåã®è²ã§ãã£ã«ã¿ãªã³ã°ãè¡ã
ã¨ã¯ã»ã«ã®ãªã¼ããã£ã«ã¿ã¼ã¯æåã®è²ã§ãã£ã«ã¿ã¼ãããããã¨ãã§ãã¾ãããè²ã¯ä¸ã¤ããæå®ã§ãã¾ãããã¾ããè¤æ°ã®ã»ã«ãé¸ãã§å³ã¯ãªãã¯ããããã£ã«ã¿ã¼ãâãé¸æããã»ã«ã®ãã©ã³ãè²ã§ãã£ã«ã¿ã¼ãããããã¨ãã¦ããè¤æ°ã®é¸æç¯å²ã«å¯¾ãã¦ã¯å®å¹ã§ããªãæ¨ã®è¦åã¡ãã»ã¼ã¸ãåºã¦ãã¾ãã¾ãã
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)ããæ¹æ³ã»ç½«ç·ã®æç¡ã§å¤å®ããæ¹æ³ï¼ããããã©ã表ã®ä½ãæ¹ã¯äººã«ãã£ã¦åå·®ä¸å¥ãªã®ã§ç¢ºå®ã«èªåé¸æã§ããä¿è¨¼ããªã・・・・・・ã
- ãã£ã«ã¿ãªã³ã°ã®è§£é¤ãé¢åã
åããã¼ã¿ã®ã»ã«ãçµåãã
ä»åã¯é£æ¥ããã»ã«ã®ãã¼ã¿ãåãã§ããã°ãã»ã«çµåãããã¨ããã³ã¼ããä½ã£ã¦ã¿ããã¨æãã¾ãã
ãããã
ãã»ã«çµåã¯ãªãã¹ãé¿ããã¹ãã
ãããã«ã»ã«çµåããããæ°ã¯æ» ãã§ã»ããã
ãæåãããã®æ©è½ãç¡ããã°ããã£ãã
ã¨ããããããªå£°ãããè³ã«ãã¾ãã
確ãã«ãå¤ãã®äººã§ãã¼ã¿ãå
±æããããããããªã¨ã¯ã»ã«ã·ã¼ãã§ããã°ãã¨ã¯ã»ã«ã®ä¾¿å©ãªæ©è½ã殺ããã¦ãã¾ããæãã¬è¿·æãããã¦ãã¾ããã¨ãããã¾ãã
ãããã使ãæ¨ã¦ã§ãä»äººã«æ¸¡ããããªãã®ã§ãªããã°ãè¦ãããããããã«ã¡ãã£ã¨ãããçµåããã£ã¦ããããããã¨ããæãããã£ãããã¾ãã
Â
å®éãç§ã¯ããããã¾ããï¼âãï¼
Â
ã ããã¨ãã£ã¦ãæåã§1åãã¤çµåãã¦ããã®ãé¢åãããã§ãããªã®ã§ã縦æ¹åï¼ã¾ãã¯æ¨ªæ¹åï¼ã«é£æ¥ããã»ã«ã®ãã¼ã¿ãåããªãã»ã«çµåãããã¨ããã³ã¼ããä½ã£ã¦ã¿ã¾ãããç¦å¿ãç©æ¥µçã«ç ´ãããã§æ°ãå¼ãã¾ããã©ã・・・・・・ã
Sub åããã¼ã¿ã®ã»ã«ãçµåãã() Dim å As Long Dim è¡ As Long Dim è¡çµ As Long Dim åçµ As Long Dim myUni As Range Application.DisplayAlerts = False If Selection.Rows.Count > 1 And Selection.Columns.Count = 1 Then 'ä¸æ¹åã«é¸æããã¨ãã®å¦ç å = Selection.Column è¡ = Selection.Row + 1 è¡çµ = Selection.Rows(Selection.Rows.Count).Row Do While è¡ <= è¡çµ If Cells(è¡ - 1, å).MergeArea(1).Value = Cells(è¡, å).MergeArea(1).Value Then If myUni Is Nothing Then Set myUni = Range(Cells(è¡ - 1, å), Cells(è¡, å)) Else Set myUni = Union(myUni, Cells(è¡, å)) End If Else If Not myUni Is Nothing Then myUni.Merge Set myUni = Nothing End If End If è¡ = è¡ + 1 Loop ElseIf Selection.Rows.Count = 1 And Selection.Columns.Count > 1 Then 'å³æ¹åã«é¸æããã¨ãã®å¦ç è¡ = Selection.Row å = Selection.Column + 1 åçµ = Selection.Columns(Selection.Columns.Count).Column Do While å <= åçµ If Cells(è¡, å - 1).MergeArea(1).Value = Cells(è¡, å).MergeArea(1).Value Then If myUni Is Nothing Then Set myUni = Range(Cells(è¡, å - 1), Cells(è¡, å)) Else Set myUni = Union(myUni, Cells(è¡, å)) End If Else If Not myUni Is Nothing Then myUni.Merge Set myUni = Nothing End If End If å = å + 1 Loop End If If Not myUni Is Nothing Then 'è¡çµã¾ãã¯åçµãå«ãã»ã«ã®çµå myUni.Merge End If End Sub
â»ã³ã¼ãã®ä½¿ç¨æ¹æ³
SubããEnd Subã¾ã§ãã³ãã¼ããæ¨æºã¢ã¸ã¥ã¼ã«çã«è²¼ãä»ãã¦ä½¿ç¨ãã¦ä¸ããããªãããã¯ãã§å®è¡ããå¦çã¯ãå ã«æ»ãããã¨ãã§ãã¾ãããå®è¡åã«ä¸æ¦ä¿åãããç´ãã®ã§ããç¶æ ã«ãã¦ããã¦ä¸ãããæ¨æºã¢ã¸ã¥ã¼ã«ã«ã³ã¼ããè²¼ãä»ãã¦ãã¯ãã使ç¨ããæ¹æ³ã¯ãã¡ãã
Â
ããã°ã©ã ã®èª¬æ
- å²æ
Â
å®è¡é¢¨æ¯
縦æ¹åã»æ¨ªæ¹åã®ã©ã¡ãå´ã«é¸æãã¦ãããã¯ããã°ã©ã ãèªåå¤å¥ãã¦ããã¾ãã
éè¨ã®æ©è½ãç ç²ã«ãã¦ãå¹é£çã«è¦ãããããã ãã®ä»æã®ãªãã³ã¼ãã§ããï¼ï¿£ï½ï¿£;ï¼
Â
 åé ã§ã触ãã¾ããããå ¬ã®å ´ã§ã»ã«çµåãä¹±ç¨ããã¨è¬ã®å¢åã«å½ãçããã¾ãã®ã§ããã®ç¹ã¯æ³¨æãã¦ä¸ããã