StarvingDog
New Member
- Joined
- May 28, 2019
- Messages
- 8
I'm trying to be more concise with my code so I've attempted to set variables instead of activating sheets as I go. However, it appears as though nothing is happening after I hit execute. The point of this sub is to copy all rows with a blank value in column "O" from two worksheets and paste this information in a separate sheet in a different workbook.
Code:
Sub Transfer_OOS()
Dim wb1 As Excel.Workbook
Set wb1 = Workbooks.Open(ThisWorkbook.Path & "\Open OOS.xlsm")
Dim wb2 As Excel.Workbook
Set wb2 = Workbooks.Open(ThisWorkbook.Path & "\Logs and Scorecard.xls*", Password:="98skv802kjsdf02")
Dim sht1 As Worksheet, sht2 As Worksheet, sht3 As Worksheet
Set sht1 = wb1.Sheets("Open OOS")
Set sht2 = wb2.Sheets("Chemistry OOS Log")
Set sht3 = wb2.Sheets("Microbiology OOS Log")
Dim c As Range
Dim Last_Row As Long
Last_Row = sht1.Range("A250").End(xlUp).Row
For Each c In sht2.Range(("O2:O") & Cells(rows.Count, "O").End(xlUp).Row)
If Not IsEmpty(c.Value) Then
Else
c.EntireRow.Copy
sht1.Activate
Cells(Last_Row + 1, 1).PasteSpecial xlValues
Cells(Last_Row + 1, 1).PasteSpecial xlFormats
End If
Last_Row = Last_Row + 1
Next c
For Each c In sht3.Range(("O2:O") & Cells(rows.Count, "O").End(xlUp).Row)
If Not IsEmpty(c.Value) Then
Else
c.EntireRow.Copy
sht1.Activate
Cells(Last_Row + 1, 1).PasteSpecial xlValues
Cells(Last_Row + 1, 1).PasteSpecial xlFormats
End If
Last_Row = Last_Row + 1
Next c
End Sub