Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,527
- Office Version
-
- 365
- 2016
- Platform
-
- Windows
I'm looking for some direction with enhancing this code:
With this code, wshmain.range("Y18") is populated with the value associated with the vlookup. However, problems exist when the vlookup fails. If the vlookup fails, I don't want to try to populate wshmain.range, just simply .protect and abandon.
Code:
Case "L18"
Dim dfcust As String
Dim wshgrp As Worksheet
Set wshmain = Worksheets("Main")
Set wshgrp = Worksheets("Group_Data")
rnum = Application.Match(Worksheets("varhold").Range("A17"), Worksheets("CONTROL_1").Range("A:A"), 0)
With Worksheets("CONTROL_1")
.Range("F" & rnum) = wshmain.Range("L18")
End With
With wshmain
.Unprotect
With .Range("Y18:AF18")
'.Locked = False
.Interior.Color = RGB(112, 156, 148)
End With
dfcust = Left(wshmain.Range("L18"), 3)
.Range("Y18") = Application.VLookup(dfcust & "*", wshgrp.Range("I:J"), 1, False)
.Protect
End With
With this code, wshmain.range("Y18") is populated with the value associated with the vlookup. However, problems exist when the vlookup fails. If the vlookup fails, I don't want to try to populate wshmain.range, just simply .protect and abandon.