snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
Option Explicit
Public Sub am()
Dim a As Single, k As Single, i As Single, j As Single, l As Single, countdateconvert As Single, iii As Single, count As Single, alldate As Single, datetonine As Variant
Dim monthtonine As Variant, c As Variant, d As Variant, countdate As Variant, jj As Variant, ii As Variant, year As Integer, allmonth As Single, monthuntilnine As Integer
On Error Resume Next
count = 1
For year = 2013 To 2014
For allmonth = 1 To 12
If monthuntilnine = allmonth < 10 Then
monthuntilnine = allmonth
monthtonine = "0" & monthuntilnine
For alldate = 6 To 31
If alldate < 10 Then
datetonine = "0" & alldate
count = count + 1
Workbooks.Open "C:\Users\somkiat\Desktop\ccc\set-history_EOD_" & 2014 & "-" & monthtonine & "-" & datetonine & "" ปัญหาอยู่บรรทัดนี้ครับ
Resume Next
For iii = 2 To 10
Workbooks("vba1").Worksheets(1).Cells(iii, count).Formula = "=VLOOKUP(A" & iii & ",'C:\Users\somkiat\Desktop\ccc\[set-history_EOD_2014-" & monthtonine & "-" & datetonine & ".csv]set-history_EOD_2014-" & monthtonine & "-" & datetonine & "'!$A$1:$G$1133,6,0)"
Next iii
Workbooks("set-history_EOD_2014-" & monthtonine & "-" & datetonine & ".csv").Close
Else '¶éÒÇѹ·ÕèäÁèãªèÇѹ·Õè1¶Ö§9 ¡ç¤×ÍÇѹ·Õè10¶Ö§31
count = count + 1 '¹Ñº¨Ó¹Ç¹Çѹ·Õèà¾ÔèÁ¢Öé¹ä»àÃ×èÍÂæ
Workbooks.Open "C:\Users\somkiat\Desktop\ccc\set-history_EOD_" & 2014 & "-" & monthtonine & "-" & alldate & "" 'à»Ô´ä¿Åì
For iii = 2 To 10 '¨Ó¹Ç¹ÃÒª×èÍËØé¹·Ñé§ËÁ´·ÕèàÅ×Í¡äÇé
Workbooks("vba1").Worksheets(1).Cells(iii, count).Formula = "=VLOOKUP(A" & iii & ",'C:\Users\somkiat\Desktop\ccc\[set-history_EOD_2014-" & monthtonine & "-" & alldate & ".csv]set-history_EOD_2014-" & monthtonine & "-" & alldate & "'!$A$1:$G$1133,6,0)" 'à¢Õ¹ÊÙµÃŧcells
Next iii
Workbooks("set-history_EOD_2014-" & monthtonine & "-" & alldate & ".csv").Close '»Ô´ä¿Åì·Õèà»Ô´
End If
Next alldate
Else '¶éÒäÁèà´×͹·Õè1¶Ö§9 ¤×Íà´×͹·Õè10¶Ö§12
For alldate = 1 To 31 'ǹÇѹ·Õè1¶Ö§31
If alldate < 10 Then 'àªç¤à§×è͹ä¢ÇèÒà»ç¹Çѹ·Õè1-9
datetonine = "0" & alldate 'ÊÃéÒ§µÑÇá»ÃÇѹà¾×èÍ·Õè¨Ð¹Óä»à»Ô´ª×èÍä¿Åì
count = count + 1 '¹Ñº¨Ó¹Ç¹Çѹ·Õèà¾ÔèÁ¢Öé¹ä»àÃ×èÍÂæ
'Workbooks.Open "C:\Users\somkiat\Desktop\ccc\set-history_EOD_" & 2014 & "-" & allmonth & "-" & datetonine & "" 'à»Ô´ä¿Åì
For iii = 2 To 10 '¨Ó¹Ç¹ÃÒª×èÍËØé¹·Ñé§ËÁ´·ÕèàÅ×Í¡äÇé
Workbooks("vba1").Worksheets(1).Cells(iii, count).Formula = "=VLOOKUP(A" & iii & ",'C:\Users\somkiat\Desktop\ccc\[set-history_EOD_2014-" & allmonth & "-" & datetonine & ".csv]set-history_EOD_2014-" & allmonth & "-" & datetonine & "'!$A$1:$G$1133,6,0)" 'à¢Õ¹ÊÙµÃŧcells
Next iii
Workbooks("set-history_EOD_2014-" & allmonth & "-" & datetonine & ".csv").Close '»Ô´ä¿Åì·Õèà»Ô´
Else '¶éÒÇѹ·ÕèäÁèãªèÇѹ·Õè1¶Ö§9 ¡ç¤×ÍÇѹ·Õè10¶Ö§31
'Workbooks.Open "C:\Users\somkiat\Desktop\ccc\set-history_EOD_" & 2014 & "-" & allmonth & "-" & alldate & "" 'à»Ô´ä¿Åì
For iii = 2 To 10 '¨Ó¹Ç¹ÃÒª×èÍËØé¹·Ñé§ËÁ´·ÕèàÅ×Í¡äÇé
Workbooks("vba1").Worksheets(1).Cells(iii, count).Formula = "=VLOOKUP(A" & iii & ",'C:\Users\somkiat\Desktop\ccc\[set-history_EOD_2014-" & allmonth & "-" & alldate & ".csv]set-history_EOD_2014-" & allmonth & "-" & alldate & "'!$A$1:$G$1133,6,0)" 'à¢Õ¹ÊÙµÃŧcells
Next iii
Workbooks("set-history_EOD_2014-" & allmonth & "-" & alldate & ".csv").Close '»Ô´ä¿Åì·Õèà»
End If
Next alldate
End If
Next allmonth
Next year
End Sub