【VBA】【EXCEL】整理指定sheet里单元格大于1/500的行列编号到新的sheet中

V20250109

Sub FindExceedingValues()
    Dim wsMax As Worksheet, wsMin As Worksheet, wsResult As Worksheet
    Dim lastRow As Long, lastCol As Long
    Dim i As Long, j As Long, resultRow As Long
    Dim point1 As String, point2 As String
    Dim startRow As Long
    
    'Set up worksheets
    Set wsMax = ThisWorkbook.Worksheets("03.diff. sett.(Max)")
    Set wsMin = ThisWorkbook.Worksheets("03.diff. sett.(Min)")
    
    'Create or clear result worksheet
    On Error Resume Next
    Set wsResult = ThisWorkbook.Worksheets("04.Over Points List")
    If wsResult Is Nothing Then
        Set wsResult = ThisWorkbook.Worksheets.Add(After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count))
        wsResult.Name = "04.Over Points List"
    End If
    On Error GoTo 0
    
    wsResult.Cells.Clear
    
    'Add headers
    wsResult.Range("A1") = "Sheet Name"
    wsResult.Range("B1") = "Point 1"
    wsResult.Range("C1") = "Point 2"
    wsResult.Range("D1") = "Value"
    
    resultRow = 2
    
    'Process Max sheet
    With wsMax
        lastRow = .Cells(.Rows.Count, "C").End(xlUp).Row
        lastCol = .Cells(4, .Columns.Count).End(xlToLeft).Column
        
        startRow = resultRow
        
        For i = 4 To lastRow
            For j = 13 To lastCol 'Starting from column M (13)
                If IsNumeric(.Cells(i, j).Value) Then
                    If .Cells(i, j).Value > 0.002 Then
                        point1 = "'" & .Cells(3, j).Text  'Use .Text to keep original format
                        point2 = "'" & .Cells(i, "C").Text
                        
                        wsResult.Cells(resultRow, "A").Value = "Max"
                        wsResult.Cells(resultRow, "B").Value = point1
                        wsResult.Cells(resultRow, "C").Value = point2
                        wsResult.Cells(resultRow, "D").Value = .Cells(i, j).Value
                        
                        resultRow = resultRow + 1
                    End If
                End If
            Next j
        Next i
        
        'Merge Max sheet cells if there are results
        If resultRow > startRow Then
            wsResult.Range("A" & startRow & ":A" & resultRow - 1).Merge
        End If
    End With
    
    'Process Min sheet
    With wsMin
        lastRow = .Cells(.Rows.Count, "C").End(xlUp).Row
        lastCol = .Cells(4, .Columns.Count).End(xlToLeft).Column
        
        startRow = resultRow
        
        For i = 4 To lastRow
            For j = 13 To lastCol 'Starting from column M (13)
                If IsNumeric(.Cells(i, j).Value) Then
                    If .Cells(i, j).Value > 0.002 Then
                        point1 = "'" & .Cells(3, j).Text  'Use .Text to keep original format
                        point2 = "'" & .Cells(i, "C").Text
                        
                        wsResult.Cells(resultRow, "A").Value = "Min"
                        wsResult.Cells(resultRow, "B").Value = point1
                        wsResult.Cells(resultRow, "C").Value = point2
                        wsResult.Cells(resultRow, "D").Value = .Cells(i, j).Value
                        
                        resultRow = resultRow 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hmywillstronger

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值