ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Detect missing rows (https://www.excelbanter.com/excel-programming/353396-detect-missing-rows.html)

Henrik Ohlsson

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.




All times are GMT +1. The time now is 12:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com