Hi there,
See if the following code does what you need:
Option Explicit
Sub CopyNames()
Const iFIRST_ROW_NO As Integer = 1
Const sCOLUMN_GRADE As String = "B"
Const sCOLUMN_NAME As String = "A"
Const sSHEETNAME As String = "Sheet1"
Dim rFillDownRange As Range
Dim rColumn_Grade As Range
Dim lLastRowNo As Long
Dim rFirstCell As Range
Dim rLastCell As Range
Dim wks As Worksheet
Set wks = ThisWorkbook.Worksheets(sSHEETNAME)
With wks
Set rColumn_Grade = Intersect(.UsedRange.EntireRow, _
.Columns(sCOLUMN_GRADE))
End With
With rColumn_Grade
lLastRowNo = .Rows(.Rows.Count).Row
End With
Set rFirstCell = wks.Range(sCOLUMN_NAME & iFIRST_ROW_NO)
Do
If rFirstCell.Offset(1, 0).Value = vbNullString Then
Set rLastCell = rFirstCell.End(xlDown).Offset(-1, 0)
If rLastCell.Row > lLastRowNo Then
Set rLastCell = wks.Range(sCOLUMN_NAME & lLastRowNo)
End If
Set rFillDownRange = Range(rFirstCell, rLastCell)
With rFillDownRange
.Value = .Cells(1, 1).Value
End With
Set rFirstCell = rLastCell.Offset(1, 0)
Else: Set rFirstCell = rFirstCell.Offset(1, 0)
End If
Loop Until rLastCell.Row = lLastRowNo
End Sub
The highlighted values may be altered to suit your own requirements.
Hope this helps - please let me know how you get on.
Regards,
Greg M
Bookmarks