Hi i need this sample excel file macro to search data in userform and insert selected account code to C4 highlighted in Yellow.
Userform should show the search results not in Excel sheet.
Thank You
Hi i need this sample excel file macro to search data in userform and insert selected account code to C4 highlighted in Yellow.
Userform should show the search results not in Excel sheet.
Thank You
Last edited by magnum4u; 01-23-2017 at 11:15 AM.
I need this macro as UserForm thanks
Sub SearchGL()
Dim arrGL() As Variant
Range("A8", "b" & Cells(Rows.CountLarge, "b").End(xlDown).Row).Clear
arrGL = FindGL(CStr(Trim(Cells(4, 3))))
Range("A8").Resize(UBound(arrGL, 2), UBound(arrGL)) = _
WorksheetFunction.Transpose(arrGL)
Columns("A:B").EntireColumn.AutoFit
End Sub
Private Function FindGL(GLNumber As String) As Variant
Dim ws As Worksheet
Dim FoundCell As Range
Dim LastCell As Range
Dim rngGL As Range
Dim FirstAddr As String
Dim arrName() As Variant
Set ws = Worksheets("GL")
Set rngGL = ws.Range("c1:c" & ws.Cells(Rows.CountLarge, "c").End(xlUp).Row)
With rngGL
Set LastCell = .Cells(.Cells.Count)
End With
Set FoundCell = rngGL.Find(What:=GLNumber, After:=LastCell, LookAt:=xlPart)
If Not FoundCell Is Nothing Then
FirstAddr = FoundCell.Address
End If
ReDim arrName(1 To 2, 1 To 1)
Do Until FoundCell Is Nothing
arrName(1, UBound(arrName, 2)) = FoundCell.Offset(0, -1)
arrName(2, UBound(arrName, 2)) = FoundCell.Value
ReDim Preserve arrName(1 To 2, 1 To UBound(arrName, 2) + 1)
Set FoundCell = rngGL.FindNext(After:=FoundCell)
If FoundCell.Address = FirstAddr Then
Exit Do
End If
Loop
FindGL = arrName
End Function
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks