Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50123

[SOLVED] Merge 2 vba codes together

$
0
0
HI I have been fighting with below codes. I have 2 codes which search in 2 different sheets (Pagado and No Pagado)
I want them to be merged, so i can search in both sheet with one code, and only one inputbox pop up and ask for the search words.

Please havea a look and see if you can merge them to one code, which can search in both sheets.

Thanks in advance
Sincerely Abjac

First code search in sheet Masterinvoice and copy complete row to sheet Pagado, the next code do the same but just copy to sheet No pagado ..


Code:

Sub SetWorksheet1()
Dim filename, sh As Worksheet, LR
Dim k As Long, j As Long
Dim myWord As String
Dim myRng As Range
Sheets("Pagado").Activate
Set sh = ThisWorkbook.Sheets("Search cliente")
LR = sh.Cells(Rows.Count, "A").End(xlUp).Row
linestart:
myWord = InputBox("Type Lastname or Firstname or Invoicenumber")
j = LR + 1
If myWord <> "" Then
  For k = 1 To Cells(Rows.Count, "F").End(xlUp).Row
    With Range("A" & k & ":AL" & k)
      Set c = .Find(myWord, LookIn:=xlValues)
      If Not c Is Nothing Then
        Sheets("Pagado").Rows(k).Copy sh.Rows(j)
        j = j + 1
       
      End If
    End With
  Next k
Else
  Exit Sub
End If
If j = LR + 1 Then

  MsgBox "Not found, Try again with another name or Invoicenumber."
 
GoTo linestart
 
End If

End Sub
Sub SetWorksheet2()
Dim filename, sh As Worksheet, LR
Dim k As Long, j As Long
Dim myWord As String
Dim myRng As Range
Sheets("No pagado").Activate
Set sh = ThisWorkbook.Sheets("Search cliente")
LR = sh.Cells(Rows.Count, "A").End(xlUp).Row
linestart:
myWord = InputBox("Type Lastname or Firstname or Invoicenumber")
j = LR + 1
If myWord <> "" Then
  For k = 1 To Cells(Rows.Count, "F").End(xlUp).Row
    With Range("A" & k & ":AL" & k)
      Set c = .Find(myWord, LookIn:=xlValues)
      If Not c Is Nothing Then
        Sheets("No pagado").Rows(k).Copy sh.Rows(j)
        j = j + 1
       
      End If
    End With
  Next k
Else
  Exit Sub
End If
If j = LR + 1 Then

  MsgBox "Not found, Try again with another name or Invoicenumber."
  GoTo linestart
 
 
End If

End Sub

Attached Files

Viewing all articles
Browse latest Browse all 50123

Trending Articles