Selection Change VBA

ashani

Active Member
Joined
Mar 14, 2020
Messages
343
Office Version
  1. 365
Platform
  1. Windows
Hi
I'm using the below formula for selection change in VBA - it works fine but everytime I click on Column A & B than it comes up with error message - Runtime error 1004. Highlights this line : Dim cel As Range: Set cel = Target.Offset(, -2)

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Selection.CountLarge > 1 Then Exit Sub
    Dim cel As Range: Set cel = Target.Offset(, -2)
    If Not Intersect(Target, Range("U7:U37")) Is Nothing Then
        If cel = "" Then
            cel.Select
            MsgBox "test"
        End If
    End If

Application.CutCopyMode = False

End Sub

Please can someone guide me.

Thank you
 
sorry yeah post 3

thanks Michael - it's working but it's selecting a cell A1 but I want to select between A8:A37 blank cells. Please can you amend that for me.

Many thanks for your help once again.
 
Upvote 0

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
What if there are no blank cells in that range?


There are blank cells in that range - actually all of them are blank currently.

I have set Data list on those cells to select but currently nothing in there, other than just a scroll button.
 
Upvote 0
What about this then?

VBA Code:
Application.Goto Reference:=Sheets("Sheet1").Range("A8:A37").SpecialCells(xlBlanks).Cells(1)
 
Upvote 0
absolutely amazeing - Thank you Peter.
you're a legend
 
Upvote 0
You're welcome. Glad it worked for you. Thanks for the generous words. :)
 
Upvote 0

Forum statistics

Threads
1,213,558
Messages
6,114,296
Members
448,564
Latest member
ED38

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