Stuck on VBA code in XL07 for Next Row

CSacles

New Member
Joined
Apr 14, 2011
Messages
11
I’m working on a VBA but I’m stuck. I was wondering if you may be able to help.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
I’m trying to do a scan program that will take me to the next row and start over after the final scan on the first row.<o:p></o:p>
<o:p> </o:p>
Here is my code<o:p></o:p>
<o:p> </o:p>
Code:
 Private Sub Worksheet_Change(ByVal Target As Range)<o:p></o:p>[/FONT][/SIZE][/COLOR]
[COLOR=#4a442a]<o:p>[FONT=Calibri][SIZE=3] [/SIZE][/FONT]</o:p>[/COLOR]
[COLOR=#4a442a][SIZE=3][FONT=Calibri]If Target.Address = "$X$1" Then<o:p></o:p>[/FONT][/SIZE][/COLOR]
[COLOR=#4a442a][SIZE=3][FONT=Calibri] Range("A2").Select<o:p></o:p>[/FONT][/SIZE][/COLOR]
[COLOR=#4a442a][SIZE=3][FONT=Calibri] Application.SendKeys "{Enter}"<o:p></o:p>[/FONT][/SIZE][/COLOR]
[COLOR=#4a442a]<o:p>[FONT=Calibri][SIZE=3] [/SIZE][/FONT]</o:p>[/COLOR]
[COLOR=#4a442a][SIZE=3][FONT=Calibri]End If<o:p></o:p>[/FONT][/SIZE][/COLOR]
[COLOR=#4a442a][SIZE=3][FONT=Calibri]If Target.Address = "$A$2" Then<o:p></o:p>[/FONT][/SIZE][/COLOR]
[COLOR=#4a442a][SIZE=3][FONT=Calibri] Range("B2").Select<o:p></o:p>[/FONT][/SIZE][/COLOR]
[COLOR=#4a442a][SIZE=3][FONT=Calibri] <o:p></o:p>[/FONT][/SIZE][/COLOR]
[COLOR=#4a442a][SIZE=3][FONT=Calibri]End If<o:p></o:p>[/FONT][/SIZE][/COLOR]
[COLOR=#4a442a][SIZE=3][FONT=Calibri]If Target.Address = "$B$2" Then<o:p></o:p>[/FONT][/SIZE][/COLOR]
[COLOR=#4a442a][SIZE=3][FONT=Calibri] Range("D2").Select<o:p></o:p>[/FONT][/SIZE][/COLOR]
[COLOR=#4a442a][SIZE=3][FONT=Calibri] <o:p></o:p>[/FONT][/SIZE][/COLOR]
[COLOR=#4a442a][SIZE=3][FONT=Calibri]    <o:p></o:p>[/FONT][/SIZE][/COLOR]
[COLOR=#4a442a][SIZE=3][FONT=Calibri]End If<o:p></o:p>[/FONT][/SIZE][/COLOR]
[COLOR=#4a442a][SIZE=3][FONT=Calibri]End Sub [END CODE]<o:p></o:p>[/FONT][/SIZE][/COLOR]
[COLOR=#4a442a]<o:p>[FONT=Calibri][SIZE=3] [/SIZE][/FONT]</o:p>[/COLOR]
[COLOR=#4a442a][SIZE=3][FONT=Calibri]I would need this program to switch fields automatically after the scan and start over on row A3.<o:p></o:p>[/FONT][/SIZE][/COLOR]
[COLOR=#4a442a][SIZE=3][FONT=Calibri]Any help is well appreciated.<o:p></o:p>[/FONT][/SIZE][/COLOR]
[COLOR=#4a442a][SIZE=3][FONT=Calibri]Thanks<o:p></o:p>[/FONT][/SIZE][/COLOR]
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Something like this?

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("X:X")) Is Nothing Then
    Range("A" & Target.Row + 1).Select
ElseIf Not Intersect(Target, Range("A:A")) Is Nothing Then
    Target.Offset(0, 1).Select
ElseIf Not Intersect(Target.Range("B:B")) Is Nothing Then
    Target.Offset(0, 2).Select
End If
End Sub
 
Upvote 0
My apologies - had a typo:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("X:X")) Is Nothing Then
    Range("A" & Target.Row + 1).Select
ElseIf Not Intersect(Target, Range("A:A")) Is Nothing Then
    Target.Offset(0, 1).Select
ElseIf Not Intersect(Target, Range("B:B")) Is Nothing Then
    Target.Offset(0, 2).Select
End If
End Sub
 
Upvote 0
For some reason, mabe it's me, but it going down to D3 instead of A3 after the last scan.

Thanks for help
 
Last edited:
Upvote 0
If I can get it to just start at the beginning of the next row, I think I will be good.

It already does that - when you change a value in column X, it will take you to column A in the next row.

Is there a different outcome that you are desiring?
 
Upvote 0
I tested it on my end. When I change A2, it goes to B2. When I change B2, it goes to D2. When I change X2, it goes to A3... and so forth.
 
Upvote 0

Forum statistics

Threads
1,224,605
Messages
6,179,860
Members
452,948
Latest member
UsmanAli786

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