Forum Discussion
edu1102
Aug 18, 2022Copper Contributor
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
this is the sample
in other words i want to get the first two ABT and paste on another file and so on and so on with the next names
thank you in advance
best regards
edu1102
2012-01-31 | ABT | 21.00 | 62 |
2012-08-17 | ABT | 26.00 | 49 |
2012-10-17 | ABT | 28.00 | 35 |
2012-11-01 | ABT | 26.00 | 63 |
2012-12-17 | ABT | 26.00 | 48 |
2012-01-03 | ACN | 44.00 | 69 |
2012-02-08 | ACN | 47.00 | 43 |
2012-06-27 | ACN | 47.00 | 55 |
2012-12-20 | ACN | 58.00 | 37 |
2012-12-27 | ACN | 56.00 | 53 |
2012-08-24 | ADBE | 32.00 | 43 |
2012-08-29 | ADBE | 32.00 | 55 |
2012-08-31 | ADBE | 31.00 | 55 |
2012-02-23 | ADI | 31.00 | 51 |
2012-03-14 | ADI | 31.00 | 44 |
2012-04-02 | ADI | 31.00 | 31 |
2012-08-22 | ADI | 31.00 | 48 |
2012-01-10 | ADM | 22.00 | 37 |
2012-01-17 | ADM | 22.00 | 43 |
2012-01-31 | ADM | 22.00 | 37 |
2012-06-19 | ADM | 23.00 | 43 |
2012-08-10 | ADM | 20.00 | 55 |
2012-10-31 | ADM | 21.00 | 61 |
2012-11-05 | ADM | 20.00 | 64 |
2012-02-07 | ADP | 38.00 | 48 |
2012-02-09 | ADP | 37.00 | 55 |
2012-05-02 | ADP | 38.00 | 52 |
2012-09-12 | ADP | 40.00 | 33 |
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.
- OliverScheurichGold Contributor
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.
- edu1102Copper Contributor
My Friend thank you for your help
Iwill credit you on this work
If you need anyhthing that i can help you
I will be at your service
best of the best
eduardo