I want to save a range of data (X8:bz8) into an array on another sheet programmatically. When the code is run, I want it to do one of three things depending on the value of two cells. I can easily express it as a formula but I'm battling to get the code right. Assume the cell values are

1. Cell "A1" (will show TRUE or FALSE), and
2. Cell "V6" (will contain a string which is a unique identifier).

Condition 1: If A1 = False and V6 already exists in a range (say C2:C5000 on another sheet), overwrite the existing data in the array with the data in X8:BZ8

Condition 2: If A1 = False and V6 does not exist in the range C2:C5000, append the data to the end of the array

Condition 3: If A1 = TRUE, show a message box saying 'the data exists and the record is closed', and do not amend or append the data from X8:BZ8 anywhere. (This should probably be the first condition tested.)

The code I have so far is:


Sub Save()

Dim sws As Worksheet, dws As Worksheet
Dim rng As Range
Dim r As Long
Dim wht
Set sws = Sheets("Admission Data Entry")
Set dws = Sheets("DatabaseAdmissions")
wht = sws.Range("v6").Value

Application.ScreenUpdating = False
sws.Range("x8:bz8").Copy
With dws.Range("c2:c5000")
   Set rng = .Find(what:=wht, LookIn:=xlValues, LookAt:=xlWhole)
   If Not rng Is Nothing Then
      r = rng.Row
   Else
      r = dws.Cells(Rows.Count, 2).End(xlUp).Row + 1
   End If
End With
dws.Range("b" & r).PasteSpecial xlPasteValues

Application.CutCopyMode = False
Range("e9").Select
Application.ScreenUpdating = True

End Sub
Any help is much appreciated.