Detect missing rows
Hi,
I've written a function "CopyFromCell" (see below) that essentially copies a
value from one cell to another, but with a feature.
I use it to copy a source table to a destination table in a worksheet. The
destination table always has the same number of rows (1-12 months), but the
source table does not always contain that many rows (months).
This is the trick; if there is a matching row(month) in the source table,
copy the value, otherwise use 0 (zero).
Public Function CopyFromCell(SourceCell As Range, MonthCell As Range) As
Variant
Set matchingMonthCell = Range("SourceMonths").Find(MonthCell.value,
LookIn:=xlValues, LookAt:=xlWhole)
If Not matchingMonthCell Is Nothing Then
CopyFromCell = SourceCell
Else
CopyFromCell = 0
End If
End Function
This works fine initially, when the source and destination tables match.
However, if I delete a row in the source table, I get a #REF! in the
destination table, since it references a cell that has just been deleted. How
do I get around this? I can still put the cursor on the desired position (say
B35) in the excel sheet.
|