vba:根据给定单元格搜索目标值

Sub 德赛()

Dim x
Dim rng As Range

Set rng = Range("$F$1:$F$1048576") '筛选目标列

If ActiveSheet.AutoFilterMode = True Then '关闭筛选模式

ActiveSheet.AutoFilterMode = False

End If

rng.AutoFilter Field:=1, Criteria1:="=*" & x & "*", Operator:=xlAnd '根据给定搜索条件筛选

For i = 1 To Range("A1").CurrentRegion.Rows.Count '将筛选结果中字符串的第8个字符开始连续6个放在第7列

c = Worksheets(1).Cells(i, 4).Value

Worksheets(1).Cells(i, 7).Value = Mid(c, 8, 6)

Next

With Range("G1:G1048576") '筛选结果居中显示
.HorizontalAlignment = xlCenter '水平居中baidu
.VerticalAlignment = xlCenter '垂直zhi居中
End With
'
'With rng

'.Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).Copy Shift:=xlShiftUp

'x = "1013B"
'ActiveSheet.Range("$F$1:$F$1048576").AutoFilter Field:=1, Criteria1:="=*" & x & "*", Operator:=xlAnd
'Set rng = Range("$F$1:$F$1048576")
'rng.Offset(1).SpecialCells(xlCellTypeVisible).Delete Shift:=xlShiftUp
End Sub

上一篇:VBA,Shapes.AddCurve SafeArrayOfPoints:=pts  画贝塞尔曲线


下一篇:Excel-VBA-质量问题可视化管理-03-删除小圆圈