[英]Select cells containing specific texts in specified row and shift cells down
我試圖在第 7 行中選擇包含字符串“NNN”、“MG”、“FS”、“N”、“IG”等的單元格,並將這些單元格向下移動。
我遇到了一個錯誤,我也不知道如何使用多個標准(“NNN”、“MG”、“FS”)進行選擇。
Sub select_text_and_shiftdown()
Dim r As Range, v As Variant
Dim w1 As Worksheet
Set w1 = Sheets("Input")
w1.Activate
For Each r In Intersect(Range("7:7"), ActiveSheet.UsedRange)
v = r.Value
If InStr(v, "NNN") > 0 Then
r.Application.Selection.inset shift = xlDown
End If
Next r
End Sub
歡迎來到 SO。 可以試試
Sub select_text_and_shiftdown()
Dim r As Range, v As Variant
Dim w1 As Worksheet
Dim Chk As Variant
Dim i As Integer
Chk = Array("NNN", "MG", "FS", "N", "IG")
Set w1 = Sheets("Input")
w1.Activate
For Each r In Intersect(Range("7:7"), ActiveSheet.UsedRange)
v = r.Value
For i = LBound(Chk) To UBound(Chk)
If InStr(v, Chk(i)) > 0 Then
'r.Application.Selection.inset shift = xlDown
r.Insert xlShiftDown
Exit For
End If
Next i
Next r
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.