Consulting

Results 1 to 8 of 8

Thread: Needs Help With For Next Loop

  1. #1
    VBAX Regular
    Joined
    Mar 2019
    Posts
    30
    Location

    Needs Help With For Next Loop

    Greetings experts,

    I need help editing this code into a for next loop.

    If Activesheet's Cell B11 is the same as any value in Column F from sheet "Vendor Code List" then Activesheet's Cell B13 value would be the value in Column E from sheet "Vendor Code List" corresponding to the same row.

    Sub AutoPopulate()
    
    
    If Range("B11") = Worksheets("Vendor Code List").Range("F") Then
    Range("B13") = Worksheets("Vendor Code List").Range("E")
    End If
    
    End Sub

    Any help is much appreciated!

  2. #2
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    479
    Location
    Sub AutoPopulate()
        Dim rng As Range
        Set rng = Sheets("Vendor Code List").Columns("f").Find([b11], lookat:=xlWhole)
        If Not rng Is Nothing Then [b13] = rng.Offset(, -1)
    End Sub

  3. #3
    VBAX Regular
    Joined
    Mar 2019
    Posts
    30
    Location
    For some reason, I can't find any.. My cell B11 in the first worksheet has a drop down data validation, is that the problem?

  4. #4
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    479
    Location
    Please refer to the attachment.
    Attached Files Attached Files

  5. #5
    VBAX Regular
    Joined
    Mar 2019
    Posts
    30
    Location
    I have tried again but I still get this error
    error.JPG

  6. #6
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    479
    Location
    Sorry, I don't know the reason, it worked well here.

  7. #7
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    479
    Location
    Maybe it's a problem caused by the use of "[ ]".
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub
    If Target.Address <> Range("b11").Address Then Exit Sub
    If Target = "" Then Exit Sub
    AutoPopulate
    End Sub
    Sub AutoPopulate()
    Dim rng As Range
    Set rng = Sheets("Vendor Code List").Columns("f").Find(Range("b11"), lookat:=xlWhole)
    If Not rng Is Nothing Then Range("b13") = rng.Offset(, -1)
    End Sub

  8. #8
    VBAX Regular
    Joined
    Mar 2019
    Posts
    30
    Location
    Hi,

    I know what was the problem. It was because I had other objects in the field and I saw that they clashed into the code when I debug.print

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •