Hello Sir
Below Macro was ok until my Data sheet (Sheet2) was below 1000
But now I have 400 records in 1st Master sheet (call it as sheet1 ) and 50000+ records in Data Sheet (call it as sheet2)
Now i do not want that it should loop through sheet1 find the value in sheet2 and if found then filter it and create PDF
Now I want that if filter is given in sheet1 it will loop only through visible cells and filter data in sheet2 create pdf name that pdf file as per cell name and mention its path +name in sheet1 so that i can be mail later
if filter is not given then it will loop all else loop only visible data of sheet1
Please Help me where the code is to be changed and how
[/CODE]
Below Macro was ok until my Data sheet (Sheet2) was below 1000
But now I have 400 records in 1st Master sheet (call it as sheet1 ) and 50000+ records in Data Sheet (call it as sheet2)
Now i do not want that it should loop through sheet1 find the value in sheet2 and if found then filter it and create PDF
Now I want that if filter is given in sheet1 it will loop only through visible cells and filter data in sheet2 create pdf name that pdf file as per cell name and mention its path +name in sheet1 so that i can be mail later
if filter is not given then it will loop all else loop only visible data of sheet1
Please Help me where the code is to be changed and how
VBA Code:
[CODE=vba]Sub splitfile()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim sh1 As Worksheet, sh2 As Worksheet, lr As Long, fn As range, sr As range, rng As range, n As Long, path As String, folder As String
Sheets("data").Select
Dim FilterCol As String: FilterCol = "B" 'The column containing the data to filter by
Dim HeaderRow As String: HeaderRow = "1" 'The row containing headers for the data
Set rngToFilter = range(FilterCol & HeaderRow, Cells(Rows.Count, FilterCol).End(xlUp))
Sheets("Master").Select
path = range("J3").Value
Set sh1 = Sheets("master")
Set sh2 = Sheets("Data")
lr = sh1.Cells(Rows.Count, 1).End(xlUp).Row
lrfn = lr + 1
Sheets("data").Select
For i = lr To 2 Step -1
Set fn = sh2.range("B:B").Find(sh1.Cells(i, 1).Value, , xlValues, xlWhole)
Application.StatusBar = "Processing Left... " & CInt(i / lrfn * 100) & "% " & String(CInt(i / lrfn * 100), ChrW(9609))
If Not fn Is Nothing Then
Set sr = fn.Offset(1, 1)
If sr <> "" And sr.Offset(1) <> "" Then
Set er = sr.End(xlDown)
Set rng = sh2.range(sr, er)
Else
Set rng = sr
End If
n = rng.Rows.Count
Sheets("data").Select
With ActiveWorkbook.Sheets("data")
rngToFilter.AutoFilter Field:=2, Criteria1:=fn.Value
End With
activesheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=path & fn.Value & ".pdf", _
quality:=xlQualityStandard, includedocproperties:=True, _
ignoreprintareas:=False, openafterpublish:=False
activesheet.AutoFilter.ShowAllData
lrow = activesheet.Cells(Rows.Count, 2).End(xlUp).Row
Sheets("Master").Select
ThisWorkbook.Sheets("Master").Cells(i, 4) = path & fn.Value & ".pdf"
ThisWorkbook.Sheets("Master").Cells(i, 5) = "Pending"
ThisWorkbook.Sheets("Master").Cells(i, 7) = lrow - 1
End If
Next
'Call createpdf
range("A2").Select
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub