So, I created a series of formula on a sheet called Extractor in a workbook called "Processor*". The filename of the workbook "Processor*" will usually vary, having other characters to the right of it. My intention is to copy the range covering all formula I created in a sheet named "Extractor" of the workbook "Processor*", and paste to another workbook "INJ*", with a filename also having variable characters to the right, and specifically to the worksheet named "Table". Upon pasting these formula, it will give results of the different cells i need from "INJ*" based on some conditions I already set in my formula. Please, note that the formula works fine when I do the copy and paste myself. Then I want to copy these results to another sheet on the "Processor*". A sheet called "calculation".
Below is the code I wrote, but I can't seem to get the object defined within the IF statement to work outside the statement. I have several of these files to work with, I will really appreciate your help. Thank you!
Sub ResultExtract()
Dim wb1 As Workbook, wb2 As Workbook, sh1 As Worksheet, sh2 As Worksheet, sh3 As Worksheet, sh4 As Worksheet, lrow As Long, lrow2 As Long, rng As Range
Dim Ct As Long
For Each WB In Application.Workbooks
wb1 = Null
If WB.Name Like "Processor*" Then
Ct = Ct + 1
WB.Activate
Set wb1 = ActiveWorkbook
Set sh1 = wb1.Sheets("Extractor")
Set sh2 = wb1.Sheets("calculation")
Exit For
End If
Next WB
If Ct = 0 Then MsgBox "File not open"
Dim Ct2 As Long
For Each WB In Application.Workbooks
If WB.Name Like "INJ*" Then
Ct2 = Ct2 + 1
WB.Activate
Set wb2 = ActiveWorkbook
Set sh3 = wb2.Sheets("Manager Report")
Set sh4 = wb2.Sheets("TABLE")
Exit For
End If
Next WB
If Ct2 = 0 Then MsgBox "File not open"
With wb1
sh1.Range("C38:J42").Copy wb2.sh4.Range("C38")
End With
With sh4
.Range("C42:J42").Copy
sh2.Range("A" & lrow2).PasteSpecial Paste:=xlPasteValuesAndNumberFormats
End With
End Sub
Below is the code I wrote, but I can't seem to get the object defined within the IF statement to work outside the statement. I have several of these files to work with, I will really appreciate your help. Thank you!
Sub ResultExtract()
Dim wb1 As Workbook, wb2 As Workbook, sh1 As Worksheet, sh2 As Worksheet, sh3 As Worksheet, sh4 As Worksheet, lrow As Long, lrow2 As Long, rng As Range
Dim Ct As Long
For Each WB In Application.Workbooks
wb1 = Null
If WB.Name Like "Processor*" Then
Ct = Ct + 1
WB.Activate
Set wb1 = ActiveWorkbook
Set sh1 = wb1.Sheets("Extractor")
Set sh2 = wb1.Sheets("calculation")
Exit For
End If
Next WB
If Ct = 0 Then MsgBox "File not open"
Dim Ct2 As Long
For Each WB In Application.Workbooks
If WB.Name Like "INJ*" Then
Ct2 = Ct2 + 1
WB.Activate
Set wb2 = ActiveWorkbook
Set sh3 = wb2.Sheets("Manager Report")
Set sh4 = wb2.Sheets("TABLE")
Exit For
End If
Next WB
If Ct2 = 0 Then MsgBox "File not open"
With wb1
sh1.Range("C38:J42").Copy wb2.sh4.Range("C38")
End With
With sh4
.Range("C42:J42").Copy
sh2.Range("A" & lrow2).PasteSpecial Paste:=xlPasteValuesAndNumberFormats
End With
End Sub