NaughtyPopz
New Member
- Joined
- Jun 27, 2023
- Messages
- 8
- Office Version
- 365
- Platform
- Windows
Hello,
I'm running this vba script:
When i click a cell in specified range, excel activates the specified worksheet and changes cell D3 on the activated sheet depending on the clicked cell in range.
The problem is, I don't want the code to run when the cell in specified range is blank. But i can't seem to get it to work.
Anyone that can help?
I'm running this vba script:
When i click a cell in specified range, excel activates the specified worksheet and changes cell D3 on the activated sheet depending on the clicked cell in range.
The problem is, I don't want the code to run when the cell in specified range is blank. But i can't seem to get it to work.
Anyone that can help?
VBA Code:
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim cRow As Integer
cRow = Range("B1048576").End(xlUp).Row
If Selection.Count = 1 Then
If Not Intersect(Target, Range("B2:B" & cRow)) Is Nothing Then
Call ChangeNameFiche
Else
Call ShowActive
End If
End If
End Sub
Private Sub ChangeNameFiche()
Dim rownum As Integer, shl As Worksheet
Set shl = Worksheets("Postbodefiche")
rownum = CDbl(ActiveCell.Row)
shl.Range("D3").Value = Range("B" & rownum).Value
ThisWorkbook.Sheets("Postbodefiche").Activate
End Sub
Private Sub ShowActive()
Dim shl As Worksheet
Set shl = Worksheets("Postbodefiche")
shl.Range("D3").Value = Range("B2").Value
End Sub