jondavis1987
Active Member
- Joined
- Dec 31, 2015
- Messages
- 443
- Office Version
- 2019
- Platform
- Windows
Below is where i have a code to create a worksheet if one does not exist. It's supposed to do the rest of the sub after this but it stops at either creating the sheet or locating the sheet if it already existed. What am i doing wrong?
VBA Code:
' Open destination workbook and capture it as destination workbook
Workbooks.Open "C:\Users\jdavis\Dropbox\Quality Control\Asphalt\Mold Heights\" & destName & ".xlsx"
Set destWB = ActiveWorkbook
On Error GoTo ErrHandler:
Worksheets(wsName).Activate
Exit Sub
ErrHandler:
If Err.Number = 9 Then
' sheet does not exist, so create it
Worksheets.Add.Name = wsName
' go back to the line of code that caused the problem
Resume
End If
' Find last row of data in desired worksheet of destination workbook
lastRow = destWB.Sheets(wsName).Cells(Rows.Count, "A").End(xlUp).Row + 1
' Copy Mold Heights data from source workbook to destination workbook
srcWB.Sheets("A").Range("G3").Copy
destWB.Sheets(wsName).Range("A" & lastRow).PasteSpecial xlPasteValues