Cell Offset using Worksheet_SelectionChange subclass

atblack22

New Member
Joined
Jun 16, 2011
Messages
10
I have a scanner that scans and tabs across to next column. Once it gets to a certain column (i.e. column D) I need it to return 1 row down, back to column B. I figured the best way to handle this would be the SelectionChange excel object in VB. However, I just attempted to just use the offset to make sure it would work correctly, and it does not. I just entered simple code of
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
ActiveCell.Offset(1,-1).Activate
End Sub
and it bombs out. I tried making them both positive number, and it will jump down a couple hundred rows and about 50 columns. Any pointers? I assumed this was the only coltrol to run my VB automatically without hitting a shortcut key, as they are scanning tons of information and that would be too repetitive. If you could also help with the if statement needed to identify active column ID that would help.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Try like this

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column >= 4 Then
    Application.EnableEvents = False
    Target.Offset(1, -2).Activate
    Application.EnableEvents = True
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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