Tricky Problem with Sequential Fill Macro
I like doing these type problems with worksheet_change functions. Add code
below as follows:
Go to excel worksheet and right click tab on bottom of sheet (normnally
sheet1).SELECT VIEW CODE. COPY AND PAST SUBROUTINE BELOW
Sub worksheet_change(ByVal Target As Range)
Application.EnableEvents = False
For Each cell In Target
If (cell.Column = 6) And _
(cell.Row = 7) Then
LastRowE = Cells(cell.Row, "E").End(xlUp).Row
LastVal = Cells(LastRowE, "E")
Prefix = Left(LastVal, 2)
Numsuffix = Val(Mid(LastVal, 3))
For RowCount = (LastRowE + 1) To cell.Row
Numsuffix = Numsuffix + 1
Cells(RowCount, "E") = Prefix + _
Format(Numsuffix, "000000")
Next RowCount
End If
Next cell
Application.EnableEvents = True
End Sub
" wrote:
Hi, Smart People.
I've encountered a tricky problem that I thought you might be able to
help with.
I'm creating a macro that needs to sequentially fill down one column,
but only as far down as the column immediately to the right of it has
text.
Here are more details:
-Text will be inserted into Column F, starting at F7 (the number of
cells filled in column F will vary).
-In cell E7, a code that is a combination of two letters and six
numbers will be inserted (e.g., BR000800). The letter prefix will
remain the same each time, but the numbers will be different.
So, if four lines of data are inserted into column B, and the code in
E7 is GS001442, then the macro needs to fill E8 through E10 with
GS001443, GS001444, and GS001445.
Any ideas how I might accomplish this? Thanks so much.
Matt
|