วางข้อมูลชุดที่ 2 แต่ไม่เริ่มที่แถวใหม่
Posted: Mon Sep 25, 2017 1:51 pm
สวัสดีครับ ผมต้องการวางข้อมูลต่อกันภายในแถว ตั้งแต่เดือน 1/17 - 12/18 แต่พอรันมาโครข้อมูลไม่เริ่มที่แถวใหม่ แต่กลับวางทับที่เดิมตลอด แบบนี้ผมต้องแก้ Code ในส่วนไหนบ้างครับ ขอบคุณมากครับ
ไฟล์แนบ
ภาพนี้เป็นตัวอย่างผลที่อยากได้ครับ
ไฟล์แนบ
ภาพนี้เป็นตัวอย่างผลที่อยากได้ครับ
Code: Select all
Sub CopyToDB()
Sheets("sheet1").Select
RowEnd = Selection.End(xlDown).Row
RowEnd = RowEnd + 1
Sheets("Sheet1").Select
Range("L3").Select
ColEnd = Selection.End(xlToRight).Column
Sheets("database").Select
Sheets("database").Range("A2").Select
RowEndDB = RowEnd
RowEndDB = RowEndDB + 1
For i = 12 To ColEnd
Sheets("sheet1").Select
Columns("K:K").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("L2").Select
Selection.Copy
Range("K3").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.AutoFill Destination:=Range("K3:K7754"), Type:=xlFillCopy
'Range("K:K7754").Select
'
Sheets("sheet1").Select
Range("A3:L3").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Range("A" & RowEndDB).Select
Worksheets("Database").Paste
Sheets("Sheet1").Select
Columns("K:L").Select
Selection.Delete Shift:=xlToLeft
Next i
End Sub