Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Find multiple values in a row and select with Macro I need find and select multi

ID: 638041 • Letter: F

Question

Find multiple values in a row and select with Macro

I need find and select multiple values in a row "B4" and copy this values and paste in other rows .

Example:

I have this values in a workbook in the row "B4"

I need find this following values:

<=30 select and copy

=31 <61 select and copy

=61 <91 select and copy

>=91 select and copy

This the results what I need when I run the macro.

I try this code but not work. Please help

Sub Multiplevalues()
Set ws = Worksheets("Sheet1")
    m = ws.Range("4", ws.Range("4").End(xlToRight)).Rows.Count
    For r = 2 To m
    Select Case m
    Case Is <= 30
        ws.Range("4" & r).Select
        Selection.Copy
        Rows(5).Select
        ActiveSheet.Paste
           Case Is = 31 < 61
        ws.Range("4" & r).Select
        Selection.Copy
         Rows(6).Select
        ActiveSheet.Paste
           Case Is = 61 < 91
        ws.Range("4" & r).Select
        Selection.Copy
         Rows(7).Select
        ActiveSheet.Paste
           Case Is >= 91
        ws.Range("4" & r).Select
        Selection.Copy
        Rows(8).Select
        ActiveSheet.Paste
       End Select
      Next r
End Sub


Thanks !!

88 1 32 3 40 60 65 90 100 123 12

Explanation / Answer

Hi..

just a clarification: "B4" is a cell (not "a row") -?-

so, I'm using [B4] as the starting cell and extending selection to the right (row 4)

try this way:

Sub ValuesDistribution()
Application.ScreenUpdating = False
Dim n As Byte, col5 As Byte, col6 As Byte, col7 As Byte, col8 As Byte
With Range([b4], [b4].End(xlToRight))
    For n = 1 To .Columns.Count
      Select Case .Cells(, n)
        Case 1 To 30
          col5 = col5 + 1
          .Cells(2, col5) = .Cells(, n)
        Case 31 To 60
          col6 = col6 + 1
          .Cells(3, col6) = .Cells(, n)
        Case 61 To 90
          col7 = col7 + 1
          .Cells(4, col7) = .Cells(, n)
        Case Is >= 91
          col8 = col8 + 1
          .Cells(5, col8) = .Cells(, n)
      End Select
    Next
End With
End Sub

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote