Created
February 17, 2025 10:01
-
-
Save hochun836/97ccedec3648c4be14f48defa97fe6fd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub CombineSelectedCells() | |
Dim selectedRange As Range | |
Dim cell As Range | |
Dim resultString As String | |
' 檢查是否有選擇的儲存格 | |
If Selection.Cells.Count > 1 Then | |
' 將選擇的儲存格合併成一個字串 | |
For Each cell In Selection | |
resultString = resultString & """" & cell.Value & """, " | |
Next cell | |
' 刪除最後一個逗號和空格 | |
resultString = Left(resultString, Len(resultString) - 2) | |
' 在 Immediate 窗口中顯示結果,或者根據需要執行其他操作 | |
Debug.Print resultString | |
Else | |
MsgBox "請選擇多個儲存格來執行此操作。" | |
End If | |
End Sub | |
Sub HighlightText() | |
Dim ws As Worksheet | |
Set ws = ThisWorkbook.Sheets("Operation Desc") | |
Dim targetTextArray As Variant | |
targetTextArray = Array(xxx) | |
Dim cell As Range | |
For Each cell In ws.UsedRange | |
Dim i As Integer | |
For i = LBound(targetTextArray) To UBound(targetTextArray) | |
Dim targetText As String | |
targetText = targetTextArray(i) | |
Dim startPosition As Integer | |
startPosition = 1 | |
Do While InStr(startPosition, cell.Value, targetText) > 0 | |
Dim position As Integer | |
position = InStr(startPosition, cell.Value, targetText) | |
cell.Characters(position, Len(targetText)).Font.Color = RGB(204, 0, 204) | |
' Move the startPosition to the next position after the current occurrence | |
startPosition = position + Len(targetText) | |
Loop | |
Next i | |
Next cell | |
End Sub | |
Sub ApplyBordersToEachRow() | |
Dim selectedRange As Range | |
Dim currentRow As Range | |
Dim cell As Range | |
Dim startCell As Range | |
Dim endCell As Range | |
' 遍歷選擇的每一行 | |
For Each currentRow In Selection.Rows | |
Set startCell = currentRow.Cells(1) | |
Set endCell = currentRow.Cells(currentRow.Cells.Count) | |
' 設置其之間區域的粗邊框 | |
With Sheets("Operation Desc").Range(startCell, endCell) | |
.Borders(xlEdgeTop).LineStyle = xlContinuous | |
.Borders(xlEdgeTop).Weight = xlMedium | |
.Borders(xlEdgeBottom).LineStyle = xlContinuous | |
.Borders(xlEdgeBottom).Weight = xlMedium | |
.Borders(xlEdgeLeft).LineStyle = xlContinuous | |
.Borders(xlEdgeLeft).Weight = xlMedium | |
.Borders(xlEdgeRight).LineStyle = xlContinuous | |
.Borders(xlEdgeRight).Weight = xlMedium | |
End With | |
Next currentRow | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment