Forum Discussion

edu1102's avatar
edu1102
Copper Contributor
Aug 18, 2022
Solved

select text from a file

dear friends  I work excel files where the column B is a text  this text repeat several columns down  question how to select the firsts two names om column b and copy and paste on another file  th...
  • OliverScheurich's avatar
    Aug 18, 2022

    edu1102 

    Sub selectrows()
    
    Dim i As Long
    Dim j As Long
    Dim k As Long
    Dim m As Long
    Dim n As Long
    
    Range("F:I").Clear
    m = 2
    i = Range("A" & Rows.Count).End(xlUp).Row
    
    For j = 2 To i
    
    n = Application.WorksheetFunction.CountIf(Range(Cells(2, 2), Cells(j, 2)), Cells(j, 2))
    
    If n = 1 Then
    
    Range(Cells(j, 1), Cells(j + 1, 4)).Copy Destination:=Cells(m, 6)
    m = m + 2
    
    Else
    
    End If
    
    Next j
    
    End Sub

    Maybe with these lines of code. In the attached file you can click the button in cell K2 to run the macro.