Don't run vba script on click when blank

NaughtyPopz

New Member
Joined
Jun 27, 2023
Messages
8
Office Version
  1. 365
Platform
  1. 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?

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
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Nestle that code within another IF statement. i.e. - If ISBLANK(Selection) Then Exit Sub Else <Do things here>End If
 
Upvote 0
Solution

Forum statistics

Threads
1,224,851
Messages
6,181,395
Members
453,034
Latest member
mikdadhussain

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top