snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
Sub PasteData()
Dim wbShare As Workbook
Dim formBook As Workbook
Dim i As Integer
Dim rs As Range
Dim rt As Range
Set formBook = ThisWorkbook
Set wbShare = Workbooks("Ph_BookShare.xlsx")
Application.ScreenUpdating = False
With formBook
i = Worksheets("Enterthedata").Range("C224")
End With
With Worksheets("Template")
Set rs = .Range(.Range("A2"), .Range("AF" & i + 1))
End With
Set rt = wbShare.Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
If Worksheets("Enterthedata").Range("C224") = True Then
MsgBox "Please check your data. This transaction already recorded."
Exit Sub
End If
If Worksheets("Enterthedata").Range("B204") = "" Then
MsgBox "Your data is empty. Fill your data and click record button again."
Exit Sub
End If
rs.Copy: rt.PasteSpecial xlPasteValues
Application.CutCopyMode = False
Sheets("Enterthedata").Range("D2,K2,B204:B219,D204:D219,L204:L219,D221,E221,E204:F219,L204:M219,O204:O219").ClearContents
With Worksheets("Enterthedata")
.Range("N1") = .Range("N1") + 1
End With
Application.ScreenUpdating = True
Windows("Ph_BookShare.xlsx").Activate
ActiveWorkbook.Save
Windows("Purchases.xlsm").Activate
ActiveWorkbook.Save
End Sub
Sub PasteData()
'Other code
Set wbShare = Workbooks("Ph_BookShare.xlsx")
wbShare.Save '<== Add this line for refresh shareworkbook
Application.ScreenUpdating = False
With formBook
i = Worksheets("Enterthedata").Range("C224")
End With
With Worksheets("Template")
Set rs = .Range(.Range("A2"), .Range("AF" & i + 1))
End With
Set rt = wbShare.Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
If Worksheets("Enterthedata").Range("C224") = True Then
MsgBox "Please check your data. This transaction already recorded."
Exit Sub
End If
If Worksheets("Enterthedata").Range("B204") = "" Then
MsgBox "Your data is empty. Fill your data and click record button again."
Exit Sub
End If
rs.Copy: rt.PasteSpecial xlPasteValues
wbShare.Save '<==Save after record data
'Other code
End Sub
ซึ่งจะเป็นไปตามที่ผมแจ้งไปคือ
Save share workbook for refresh before record data
Sub PasteData()
Dim wbShare As Workbook
Dim formBook As Workbook
Dim i As Integer
Dim rs As Range
Dim rt As Range
Set formBook = ThisWorkbook
Set wbShare = Workbooks("AA_BookShare.xlsx")
wbShare.Save '<== Add this line for refresh shareworkbook
Application.ScreenUpdating = False
With formBook
i = Worksheets("Enterthedata").Range("C224")
End With
With Worksheets("Template")
Set rs = .Range(.Range("A2"), .Range("AF" & i + 1))
End With
Set rt = wbShare.Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
If Worksheets("Enterthedata").Range("C224") = True Then
MsgBox "Please check your data. This transaction already recorded."
Exit Sub
End If
If Worksheets("Enterthedata").Range("B204") = "" Then
MsgBox "Your data is empty. Fill your data and click record button again."
Exit Sub
End If
rs.Copy: rt.PasteSpecial xlPasteValues
wbShare.Save '<==Save after record data
formBook.Save
Application.CutCopyMode = False
Sheets("Enterthedata").Range("D2,K2,B204:B219,D204:D219,L204:L219,D221,E221,E204:F219,L204:M219,O204:O219").ClearContents
With Worksheets("Enterthedata")
.Range("N1") = .Range("N1") + 1
End With
End Sub
ขอรบกวนช่วยแก้เมื่อใช้ Form บันทึกข้อมูลไปที่แชร์ไฟล์พร้อมกันแล้วเลขที่เอกสารที่เซลล์ N1 ชีท Enterthedata ต้วอย่างไฟล์แนบไม่อัพเดทค่ะ
Sub PasteData()
Dim wbShare As Workbook
Dim formBook As Workbook
Dim i As Integer
Dim e As Integer 'เพื่อทดลองหาตัวเลขล่าสุด
Dim rs As Range
Dim rt As Range
Set formBook = ThisWorkbook
Set wbShare = Workbooks("AA_BookShare.xlsx")
With wbShare
e = Workbooks.Function.CountA("sheet1").Range("B:B).Columns("E:E")))
End With
wbShare.Save '<== Add this line for refresh shareworkbook
Sub PasteData()
Dim wbShare As Workbook
Dim formBook As Workbook
Dim i As Integer
Dim rs As Range
Dim rt As Range
Set formBook = ThisWorkbook
Set wbShare = Workbooks("AA_BookShare.xlsx")
wbShare.Save '<== Add this line for refresh shareworkbook
Application.ScreenUpdating = False
With formBook
i = Worksheets("Enterthedata").Range("C224")
End With
With Worksheets("Template")
Set rs = .Range(.Range("A2"), .Range("AF" & i + 1))
End With
Set rt = wbShare.Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
If Worksheets("Enterthedata").Range("C224") = True Then
MsgBox "Please check your data. This transaction already recorded."
Exit Sub
End If
If Worksheets("Enterthedata").Range("B204") = "" Then
MsgBox "Your data is empty. Fill your data and click record button again."
Exit Sub
End If
rs.Copy: rt.PasteSpecial xlPasteValues
wbShare.Save '<==Save after record data
formBook.Save
Application.CutCopyMode = False
Sheets("Enterthedata").Range("D2,K2,B204:B219,D204:D219,L204:L219,D221,E221,E204:F219,L204:M219,O204:O219").ClearContents
With Worksheets("Enterthedata")
.Range("N1") = .Range("N1") + 1
End With
End Su
You do not have the required permissions to view the files attached to this post.