modifying a macro

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
Hello everyone, I have this challenge here and I want you to help me out.
This is filling the textboxes when double clicked.
Code:
Private Sub lstView_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    Dim n As Integer, ac As Integer, i As Integer
        i = Me.lstView.ListIndex
            With lstView
                For ac = 1 To .ColumnCount
                    .TextColumn = ac
                        Me.Controls("Rw" & ac).Value = .Text
                    Next ac
                CmdEdit.Enabled = True
            CmdDelete.Enabled = True
        CmdAdd.Enabled = False
    End With
End Sub

This one is the next button:
Code:
Private Sub CmdNext_Click()
    Dim FindRow As Range, i As Long, cNum As Long, x As Long, r As Long, cRow As String, sht As String
    sht = ComboBox1.Value
    On Error Resume Next
    cRow = Me.Rw1.Value
    Set FindRow = Sheets(sht).Range("B7:B250").Find(What:=cRow, LookIn:=xlValues)
        If FindRow Is Nothing Then Exit Sub
        
          r = IIf(Len(FindRow.Offset(1, 0).Text) = 0, 0, 1)
    
    cNum = 22
    For x = 1 To cNum
        Me.Controls("Rw" & x).Value = FindRow.Offset(r, 0).Text
    Set FindRow = FindRow.Offset(0, 1)
    
    Next
    If r = 0 Then MsgBox "Last Record reached in the database", vbInformation, "Last Record Alert!"
    On Error GoTo 0
End Sub

This one populates the listbox:
Code:
Sub Lookup()
    On Error GoTo errHandler:
        lstView.ColumnCount = 22
            Dim myArray As Variant
                myArray = [B2].Resize(, lstView.ColumnCount + 2).Value
                    lstView.List = myArray
                        lstView.Clear
                    sht = ComboBox1.Value
                With Sheets(sht).Range("B7:B250")
            Set rngFind = .Find(txtSearch.Text, After:=Sheets(sht).[B250], LookIn:=xlValues, lookat:=xlPart, _
        SearchDirection:=xlNext)
    If Not rngFind Is Nothing Then
strFirstFind = rngFind.Address
Do
    If rngFind.Row > 1 Then
        lstView.AddItem rngFind.Text
            For i = 1 To 22
                lstView.List(lstView.ListCount - 1, i) = rngFind.Offset(0, i).Text
                    Next i
                        End If
                            Set rngFind = .FindNext(rngFind)
                        Loop While Not rngFind Is Nothing And rngFind.Address <> strFirstFind
                    Else: 'Reset1
                MsgBox "No match found for: " & "'" & txtSearch.Text & "'", vbInformation, "Match Alert"
            End If
        End With
    On Error GoTo 0
Exit Sub
errHandler::
    MsgBox "Check your entry for errors"
End Sub

So my mission now is to get the selection move in the listbox as I click the next button.
Thanks
Kelly
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Okay i think i have solved this issue. I used a different code for the next button and i am cool with it. Thanks
Kelly
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,897
Members
449,097
Latest member
dbomb1414

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