Hi All,
I am trying to check the range of F5:F7 whether it contains a value or not, if it is a value, I will extract the sheets according to its respective range in E5:E7. The workbook where the worksheets is extracted is in range A1. I have tested my coding to extract the worksheets from the workbook and so on, it works, except for the part that I highlighted. This is an addition so it goes through the for loop and if instead of putting the name of the sheets manually. Please take a look and give me a feedback. Thanks in advance
Sub test()
Dim Bk As String
Dim ws As Worksheet
Dim strFldrPath As String
Dim mycheck As Boolean
Dim wk As String
Bk = Sheets("Sheet1").Cells(1, 1).Value
strFldrPath = Sheets("Sheet1").Cells(2, 1).Value
wk = Sheets("Sheet1").Cells(i, 5).Value
'opening Workbook
Workbooks.Open Filename:=strFldrPath
'Removes all worksheets in this workbook so that new ones can be pulled in
Application.DisplayAlerts = False
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Sheet1" And ws.Name <> "Sheet2" Then
ws.Delete
End If
Next ws
Application.DisplayAlerts = True
Set wb = Workbooks(Bk)
endrange = 10
For i = 5 To endrange
mycheck = Sheets("Sheet1").Range("F" & i).Value = 1
If mycheck = True Then wb.Sheets(wk).Copy After:=Workbooks("Book1 .xls").Sheets("Sheet1")
Next i
End Sub
Bookmarks