The use of code tags makes it easier for others to see your code.
To place code in code tags click to edit your post --> highlight the section of code --> click on the hashtag button or pound symbol in the WYSIWYG editor.
You should really declare and initialize variables to avoid confusion. For example...
Option Explicit 'This will keep you from a lot of errors by forcing you to declare the variables used in the code
Sub Invoice_Data_CopyPaste()
'Declare variables
Dim wbInvTemp As Workbook, wbInvSum As Workbook
Dim wsInvTemp As Worksheet, wsInvSum As Worksheet
Dim InvSumS As String
Dim open_wkb_check As Boolean
Application.ScreenUpdating = False
Set wbInvTemp = ThisWorkbook
Set wsInvTemp = wbInvTemp.Worksheets("Invoice")
InvSumS = "C:\Users\PathName...\InvoiceSummary_CompanyName.xlsx"
open_wkb_check = IsWorkBookOpen(InvSumS) 'this calls the function shown below this sub
If open_wkb_check = False Then
Set wbInvSum = Workbooks.Open(InvSumS) 'note path names are not real
Else 'What if the workbook is open
Set wbInvSum = Workbooks("InvoiceSummary_CompanyName.xlsx")
End If
Set wsInvSum = wbInvSum.Worksheets("Invoice Summary List")
'The code gets hung up at this line (below)
'rather than copy and paste why not equate the values this saves resources and is faster
wsInvTemp.Range("H4").Value = wsInvSum.Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value
wsInvTemp.Range("H2").Value = wsInvSum.Range("B" & Rows.Count).End(xlUp).Offset(1, 0).Value
'etc....
''''''''''Workbooks("InvoiceTemplate_CompanyName").Worksheets("Invoice").Range("H4").Copy 'this worksheet is found in "InvoiceTemplate_CompanyName.xlsm". Users will have this open when code is run
'''''''''Workbooks("InvoiceSummary_CompanyName").Worksheets("Invoice Summary List").Range("A3").End(xlDown).Offset(1, 0) _
'''''''''.PasteSpecial Paste:=xlPasteValues
'''''''''Workbooks("InvoiceTemplate_CompanyName").Worksheets("Invoice").Range("H2").Copy
'''''''''Workbooks("InvoiceSummary_CompanyName").Worksheets("Invoice Summary List").Range("B3").End(xlDown).Offset(1, 0) _
'''''''''.PasteSpecial Paste:=xlPasteValues
'....code continues copying and pasting other values between the two workbooks
End Sub
'This function is used to see if "InvoiceSummary_CompanyName.xlsx" is already open or not.
Function IsWorkBookOpen(FileName As String)
Dim ff As Long, ErrNo As Long
On Error Resume Next
ff = FreeFile()
Open FileName For Input Lock Read As #ff
Close ff
ErrNo = Err
On Error GoTo 0
Select Case ErrNo
Case 0: IsWorkBookOpen = False
Case 70: IsWorkBookOpen = True
Case Else: Error ErrNo
End Select
End Function
By declaring and initializing your variables clearly you can always refer to exactly what you want at any time in the code easily
Bookmarks