snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
Sub Macro1()
Dim sr As Range, tg As Range, i As Integer
Set tg = Sheets("Sheet1").Range("A3:d5")
Set sr = Sheets("Sheet2").Range("b3:e5")
i = 1
For Each r In tg
If r.MergeCells Then
r.MergeArea.ClearContents
r.MergeArea.Value = sr(i).Value
Else
r.ClearContents
r.Value = sr(i).Value
End If
i = i + 1
Next r
End Sub
Sub Macro2()
Dim fileToOpen As Variant
Dim fileFilterPattern As String
Dim wsMaster As Worksheet
Dim wbTextImport As Workbook
Dim sr As Range, tg As Range, i As Integer
If MsgBox("คุณต้องการนำเข้าข้อมูลใช่หรือไม่?", 36, "ยืนยันการนำบันทึกรับจ่ายเงิน") = 6 Then
fileToOpen = Application.GetOpenFilename(Title:="เปิดไฟล์ .csv เพื่อนำเข้าข้อมูล", FileFilter:="Text Files (*.txt; *.csv),*.txt;*.csv")
Set tg = ActiveSheet.Range("A3:D5")
Set sr = wbTextImport.Worksheets("data").Range("A2:D4")
i = 1
For Each r In tg
If r.MergeCells Then
r.MergeArea.ClearContents
r.MergeArea.Value = sr(i).Value
Else
r.ClearContents
r.Value = sr(i).Value
End If
i = i + 1
Next r
End If
End Sub
You do not have the required permissions to view the files attached to this post.
Sub Macro2()
Dim fileToOpen As Variant
Dim fileFilterPattern As String
Dim wsMaster As Worksheet
Dim wbTextImport As Workbook
Dim sr As Range, tg As Range, i As Integer
Set tg = ActiveSheet.Range("A3:D5")
If MsgBox("คุณต้องการนำเข้าข้อมูลใช่หรือไม่?", 36, "ยืนยันการนำบันทึกรับจ่ายเงิน") = 6 Then
fileToOpen = Application.GetOpenFilename(Title:="เปิดไฟล์ .csv เพื่อนำเข้าข้อมูล", FileFilter:="Text Files (*.txt; *.csv),*.txt;*.csv")
Set wbTextImport = Workbooks.Open(fileToOpen)
Set sr = wbTextImport.Worksheets("data").Range("A2:D4")
i = 1
For Each r In tg
If r.MergeCells Then
r.MergeArea.ClearContents
r.MergeArea.Value = sr(i).Value
Else
r.ClearContents
r.Value = sr(i).Value
End If
i = i + 1
Next r
End If
wbTextImport.Close False
End Sub