Microsoft Developer Network > Página Inicial dos Fóruns > Visual Basic for Applications (VBA) > How can I find a minimum value in a range of data in excel
Fazer uma PerguntaFazer uma Pergunta
 

RespondidoHow can I find a minimum value in a range of data in excel

  • quinta-feira, 2 de julho de 2009 14:47solmaz moshiri Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    How can I find a minimum value in a range of data in excel, select the select first to see where it is and then omit that value from the range and then do this process again for the next minimum value? so that in the end I can omit for example 100 minimum values from a range of 1000 values

Respostas

  • domingo, 12 de julho de 2009 2:19ShasurMVPMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Respondido

    Hi

    Instead of

    cell.Select

    cell.Offset(0, -2).Select
    ActiveCell.Interior.ColorIndex = 34
    ActiveCell.Cut
    ThisWorkbook.Sheets("D2").Cells(a, 1).Select
    ActiveSheet.Paste

    You can try the following

    cell.Offset(0, -2).Cut Destination:=ThisWorkbook.Sheets("D2").Cells(a, 1)

    Cheers
    Shasur


    http://www.vbadud.blogspot.com

Todas as Respostas

  • quinta-feira, 2 de julho de 2009 15:11ADG Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     

    Hi, not exactly sure what you are trying to do but he below might give you some ideas:


    Public Sub test(rng As Range)
    Dim minValue
    Dim lngCounter As Long

    lngCounter = 0
    While lngCounter < 100
        minValue = Application.WorksheetFunction.Min(rng)
       
        Debug.Print minValue
        For Each c In rng
            If c.Value = minValue And lngCounter < 100 Then
                c.ClearContents
                 lngCounter = lngCounter + 1
            End If
        Next
    Wend
    End Sub

  • sexta-feira, 3 de julho de 2009 2:06ShasurMVPMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    you can try something like

    c.copy destination:=Range("L2")

    Cheers
    Shasur
    http://www.vbadud.blogspot.com
  • sexta-feira, 3 de julho de 2009 11:47solmaz moshiri Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    Hi again Shasur, thanks for your help yesterday, I changed your code to the following but it does not work, I'm foolishly playing with it but it does not understand: cell.select

    what I want to do is to find for example 5 minimums in the range D1:D8761. then cut this value and the values in the same row in the B and C columns and paste them all in another sheet.

    Sub Claim()
    Dim minval As Single, alfa As Range, a, b As Integer

    Set alfa = ThisWorkbook.Sheets("Energy Profit").Range("D1:D8761")

    a = 1

    lngCounter = 0

    While lngCounter < 5
    minval = Application.WorksheetFunction.min(alfa)

    For Each cell In alfa
    If cell.Value = minval And lngCounter < 5 Then
    cell.Select

    cell.Offset(0, -2).Select
    ActiveCell.Interior.ColorIndex = 34
    ActiveCell.Cut
    ThisWorkbook.Sheets("D2").Cells(a, 1).Select
    ActiveSheet.Paste

    cell.Offset(0, -1).Select
    ActiveCell.Cut
    ThisWorkbook.Sheets("D2").Cells(a, 2).Select
    ActiveSheet.Paste

    cell.Select
    cell.Cut
    ThisWorkbook.Sheets("D2").Cells(a, 3).Select
    ActiveSheet.Paste

    a = a + 1

    lngCounter = lngCounter + 1
    End If
    Next
    Wend

    End Sub
  • domingo, 12 de julho de 2009 2:19ShasurMVPMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Respondido

    Hi

    Instead of

    cell.Select

    cell.Offset(0, -2).Select
    ActiveCell.Interior.ColorIndex = 34
    ActiveCell.Cut
    ThisWorkbook.Sheets("D2").Cells(a, 1).Select
    ActiveSheet.Paste

    You can try the following

    cell.Offset(0, -2).Cut Destination:=ThisWorkbook.Sheets("D2").Cells(a, 1)

    Cheers
    Shasur


    http://www.vbadud.blogspot.com