Is this code written correctly; Private Sub WorksheetSelectionChange(ByVal Target As…
- User
Is this code written correctly; Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.CountLarge > 1 Then Exit Sub
If Target.Column = 3 And Target.Offset(0, 1).Value <> "" Then Call DispalyServices End If End SubSub DisplayServices() Dim cellValue As String Dim ws As Worksheet
' Get the value of cell Target Cell cellValue = Target.Offest(0, 1).Value
' Check if the value is a valid sheet name On Error Resume Next Set ws = Worksheets(cellValue) On Error GoTo 0
' If the sheet exists, capture values from column N If Not ws Is Nothing Then cellValue1 = ws.Range("N1").Value cellValue2 = ws.Range("N2").Value cellValue3 = ws.Range("N3").Value cellValue4 = ws.Range("N4").Value cellValue5 = ws.Range("N5").Value cellValue6 = ws.Range("N6").Value cellValue7 = ws.Range("N7").Value cellValue8 = ws.Range("N8").Value cellValue9 = ws.Range("N9").Value cellValue10 = ws.Range("N10").Value cellValue11 = ws.Range("N11").Value cellValue12 = ws.Range("N12").Value cellValue13 = ws.Range("N13").Value cellValue14 = ws.Range("N14").Value cellValue15 = ws.Range("N15").Value
' Display the captured values in a pop-up message box MsgBox "" & cellValue1 & vbCrLf & _ "" & cellValue2 & vbCrLf & _ "" & cellValue3 & vbCrLf & _ "" & cellValue4 & vbCrLf & _ "" & cellValue5 & vbCrLf & _ "" & cellValue6 & vbCrLf & _ "" & cellValue7 & vbCrLf & _ "" & cellValue8 & vbCrLf & _ "" & cellValue9 & vbCrLf & _ "" & cellValue10 & vbCrLf & _ "" & cellValue11 & vbCrLf & _ "" & cellValue12 & vbCrLf & _ "" & cellValue13 & vbCrLf & _ "" & cellValue14 & vbCrLf & _ "" & cellValue15 Else ' If the sheet does not exist, display an error message MsgBox "Invalid sheet name!" End If End Sub
- Assistant
No, the code has several errors. Here's the corrected version: