help debugging code

jfrontera

New Member
Joined
Apr 27, 2011
Messages
2
this is my code:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Rows.Count <> 1 Or Target.Row = 1 Then Exit Sub
    If Target.Offset(-1, 0) = Range("A1") Then Exit Sub
    If Target.Column <> 8 Or Target.Offset(-1, 0).Value = "" Or Target = Range("H1") Then Exit Sub
    With Range("B1:B" & Rows.Count)
        Set b = .Find(Target.Offset(-1, 0).Value, LookAt:=xlWhole)
        If Not b Is Nothing Then
            b.Offset(0, -1) = Target.Offset(-1, 0)
            Target.Offset(-1, 0) = ""
        Else
            'MsgBox "Code not found"
            If Range("H3") = "" Then
                Range("H3") = Target.Offset(-1, 0).Value
                Range("H1") = ""
            Else
                Range("H" & Rows.Count).End(xlUp).Offset(1, 0) = Target.Offset(-1, 0).Value
                Range("H1") = ""
            End If
        End If
    End With
    Target.Offset(-1, 0).Select
End Sub

I'm using the code to run an inventory I have a list of serial numbers of items i should have on hand
in col B. col A is blank for now. and i use Cell H1 as my entry point if you will. C-G have other stuff in them.
this is essentially what it looks like to begin with

34
76
89
56
02
69
101
75
200
369

I enter a number into H1, it searches col B if finds a match it places it into coresponding cell in Col A, if no match it places into H3, either way H1 resets and awaits the next entry. Subsequent non-matches just continue down col H.

A B H
3 (this is where i enter numbers)
9 9 (H2 blank for spacer, could just use a different col.
27 175
100 100 460

it's the col H where i have my problem.
you'll have to run the code to check it out;
Let's say the number 460 was supposed to be 469, you'll have to do it to see my problem: click on the cell with 460 and watch what happens. it's too hard for me to explain here.
Thanks for any help.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
you'll have to forgive i'm have posting problems too. it appears the entire code didn't make it in my post and my cols are all outta whack. I'll try the code again.

essentially enter random #s in col B enter one of those #s in H1 and watch what happens. enter a # in H1 that is not in col B and watch what happens. enter another # in H1 that isn't in col B and watch again.
now click on the # in H4 to delete the # that showed up and watch again.

That's my problem


Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Rows.Count <> 1 Or Target.Row = 1 Then Exit Sub
    If Target.Offset(-1, 0) = Range("A2") Then Exit Sub
    If Target.Column <> 8 Or Target.Offset(-1, 0).Value = "" Or Target = Range("H1") Then Exit Sub
    With Range("B1:B" & Rows.Count)
        Set b = .Find(Target.Offset(-1, 0).Value, LookAt:=xlWhole)
        If Not b Is Nothing Then
            b.Offset(0, -1) = Target.Offset(-1, 0)
            Target.Offset(-1, 0) = ""
        Else
            MsgBox "No match found"
            If Range("H3") = "" Then
               Range("H3") = Target.Offset(-1, 0).Value
               Range("H1") = ""
            Else
                Range("H" & Rows.Count).End(xlUp).Offset(1, 0) = Target.Offset(-1, 0).Value
                Range("H1") = ""
            End If
        End If
    End With
    Target.Offset(-1, 0).Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,881
Members
452,948
Latest member
Dupuhini

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