I am trying to auto populate cells in column "R" based on the value in column "A". So if cell "A8" = "ABC" then cell "R8"= "XYZ". If cell "A8" is cleared then cell "R8" is cleared too. I have a dropdown data validation list in Cell "A8". My code is working halfway but gives me a couple of errors.
I get "Type Mismatch" when I put "Valve" in cell "A8"
I also get "Method 'Range' of object'_Worksheet" failed Error '1004'
Both errors occur on the same line....
Here is what I have thus far.....
I get "Type Mismatch" when I put "Valve" in cell "A8"
I also get "Method 'Range' of object'_Worksheet" failed Error '1004'
Both errors occur on the same line....
Here is what I have thus far.....
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim RowCount As Long, Sht As Worksheet
Set Sht = Sheets("WorkSheet-1")
If Not Intersect(Target, Range("A8:A51")) Is Nothing Then
MinIsoMethodSelection
End If
If Target.Value = "" And Target.Cells.Count = 1 And Not Intersect(Target, Range("A8:A51")) Is Nothing Then
Sht.Range("S" & Target.row).ClearContents
End If
End Sub
Private Sub MinIsoMethodSelection()
Dim RowCount As Long, Sht As Worksheet
Set Sht = Sheets("WorkSheet-1")
With Sht
If .Range("A8").Value <> "" And .Range("A9").Value = "" Then
RowCount = 8
ElseIf .Range("A8").Value <> "" And .Range("A9").Value <> "" Then
RowCount = .Range("A8").End(xlDown).row
End If
If .Range("A" & RowCount).Offset(0, 17).Value = "PBB" Then 'Where Errors occur
.Range("A" & RowCount).Offset(0, 18).Value = "B"
ElseIf .Range("A" & RowCount).Offset(0, 17).Value = "AG" Then
.Range("A" & RowCount).Offset(0, 18).Value = "AG"
ElseIf .Range("A" & RowCount).Offset(0, 17).Value = "EB" Then
.Range("A" & RowCount).Offset(0, 18).Value = "B"
ElseIf .Range("A" & RowCount).Offset(0, 17).Value = "B" Then
.Range("A" & RowCount).Offset(0, 18).Value = "B"
ElseIf .Range("A" & RowCount).Offset(0, 17).Value = "CD" Then
.Range("A" & RowCount).Offset(0, 18).Value = "CD"
ElseIf .Range("A" & RowCount).Offset(0, 17).Value = "ARP" Then
.Range("A" & RowCount).Offset(0, 18).Value = "ARP"
ElseIf .Range("A" & RowCount).Offset(0, 17).Value = "SV" Then
.Range("A" & RowCount).Offset(0, 18).Value = "SV"
ElseIf .Range("A" & RowCount).Offset(0, 17).Value = "V" Then
.Range("A" & RowCount).Offset(0, 18).Value = "" 'equal nothing
End If
End With
End Sub