how to select two names in column

edu1102

New Member
Joined
Aug 18, 2022
Messages
1
Office Version
  1. 2010
Platform
  1. Windows
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

edu

2012-01-31ABT21.00
2012-08-17ABT26.00
2012-10-17ABT28.00
2012-11-01ABT26.00
2012-12-17ABT26.00
2012-01-03ACN44.00
2012-02-08ACN47.00
2012-06-27ACN47.00
2012-12-20ACN58.00
2012-12-27ACN56.00
2012-08-24ADBE32.00
2012-08-29ADBE32.00
2012-08-31ADBE31.00
2012-02-23ADI31.00
2012-03-14ADI31.00
2012-04-02ADI31.00
2012-08-22ADI31.00
2012-01-10ADM22.00
2012-01-17ADM22.00
2012-01-31ADM22.00
2012-06-19ADM23.00
2012-08-10ADM20.00
2012-10-31ADM21.00
2012-11-05ADM20.00
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
How large (how many Rows) is the range of data?
 
Upvote 0
This might be a solution.
Change references where required.
Code:
Sub Maybe_So()
Dim i As Long, j As Long, myAreas As Areas
Dim sh1 As Worksheet, sh2 As Worksheet
Set sh1 = Worksheets("Sheet1")
Set sh2 = Worksheets("Sheet3")
Application.ScreenUpdating = False
    For i = sh1.Cells(sh1.Rows.Count, 1).End(xlUp).Row To 3 Step -1
        If sh1.Cells(i, 2).Offset(-1).Value <> sh1.Cells(i, 2) Then sh1.Cells(i, 2).EntireRow.Insert Shift:=xlDown
    Next i
Set myAreas = sh1.Range("A2:C" & sh1.Cells(sh1.Rows.Count, 3).End(xlUp).Row).SpecialCells(2).Areas
    For j = 1 To myAreas.Count
        If myAreas(j).Rows.Count >= 2 Then
            myAreas(j).Cells(1).Resize(2, 3).Copy sh2.Cells(sh2.Rows.Count, 1).End(xlUp).Offset(1)
        End If
    Next j
sh1.Columns(1).SpecialCells(4).EntireRow.Delete Shift:=xlUp
Application.ScreenUpdating = True
End Sub
 
Upvote 0
If temporary inserting rows (as in code in Post #3) is not an option, this might do.
Don't know how fast or slow it is though.
Code:
Sub Maybe_So_Alternative()
Dim i As Long
Dim sh1 As Worksheet, sh2 As Worksheet
Set sh1 = Worksheets("Sheet1")
Set sh2 = Worksheets("Sheet3")
Application.ScreenUpdating = False
    For i = 2 To sh1.Cells(sh1.Rows.Count, 1).End(xlUp).Row - 1
        If sh1.Cells(i, 2).Offset(-1).Value <> sh1.Cells(i, 2).Value And sh1.Cells(i, 2).Offset(1).Value = sh1.Cells(i, 2).Value Then
            sh1.Cells(i, 1).Resize(2, 3).Copy sh2.Cells(sh2.Rows.Count, 1).End(xlUp).Offset(1)
        End If
    Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0
After you had a month to test, do you think you can let us know if any of the suggestions work.
That would be nice.
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,121
Members
452,381
Latest member
Nova88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top