Estoy buscando un código de bucle que me proporcione la primera y la última fila de un 'Nombre' en la columna A.
A
1 Phill
2 Phill
3 Phill
4 Phill
5 Phill
6 Phill
7 Matthew
8 Matthew
9 Matthew
10 Matthew
11 Hendry
12 Hendry
13 Hendry
etc. etc.
Los resultados deberían ser algo como esto en otra hoja:
A B C
1 Name Start_Row End_Row
2 Phill 1 6
3 Matthew 7 10
4 Hendry 11 13
5 etc. etc. etc.
Experimenté con diferentes bucles, pero parece que no puedo obtener el buen código de bucle que me permite comenzar. Esto es lo que tengo:
If wsData.Cells(i + DOF, 1) <> curName Then
wbMain.Activate
For i = 1 To LastRow
curName = wsData.Cells(i + DOF, 1).Value
NameCount = NameCount + 1
wbWellsTable.Sheets("Sheet1").Cells(NameCount + 1, 1) = wbMain.Sheets("Data").Rows(i + DOF)
Start_Row = wsData.Cells(i + DOF, 1).Value
Counter = Counter + 1
wbWellsTable.Sheets("Sheet1").Cells(Counter + 1, 2) = wbMain.Sheets("Data").Rows(i + DOF)
End_Row = wsData.Cells(i + DOF, 1).Value
Bounter = Bounter + 1
wbWellsTable.Sheets("Sheet1").Cells(Bounter + 1, 3) = wbMain.Sheets("Data").Rows(i + DOF)
Next i
End If
¡Espero que ustedes puedan ayudarme!
Con VBA:
Option Explicit
Sub rowfinder()
Dim ws As Worksheet
Dim rng As Range
Dim cell As Range
Dim currentName As String
Dim currentMin As Integer
Dim startRow As Integer
Dim startColumn As Integer
Dim outputColumn As Integer
Dim outputRow As Integer
Set ws = ThisWorkbook.Worksheets(1)
startRow = 2
startColumn = 1
outputColumn = 2
outputRow = 2
ws.Cells(startRow + 1, startColumn).End(xlDown).Select
Set rng = ws.Range(ws.Cells(startRow + 1, startColumn), ws.Cells(startRow + 1, startColumn).End(xlDown))
currentName = ws.Cells(startRow, startColumn).Value
currentMin = Cells(startRow, startColumn).Row
ws.Cells(outputRow, outputColumn).Value = currentName
ws.Cells(outputRow, outputColumn + 1).Value = currentMin
For Each cell In rng
If cell.Value <> currentName Then
ws.Cells(outputRow, outputColumn + 2).Value = cell.Row - 1
currentName = cell.Value
currentMin = cell.Row
outputRow = outputRow + 1
ws.Cells(outputRow, outputColumn).Value = currentName
ws.Cells(outputRow, outputColumn + 1).Value = currentMin
End If
Next cell
Set cell = rng.End(xlDown)
ws.Cells(outputRow, outputColumn + 2).Value = cell.Row
End Sub
Este artículo se recopila de Internet, indique la fuente cuando se vuelva a imprimir.
En caso de infracción, por favor [email protected] Eliminar
Déjame decir algunas palabras