Page 1 of 1

Macros รัน ข้อมูลผิดไม่เหมือนตอน Record ครับ (มีตัวอย่างครับ)

Posted: Wed Jan 05, 2022 3:32 pm
by ballkoong
Macros รัน ข้อมูลผิดไม่เหมือนตอน Record ครับ (มีตัวอย่างครับ)
เช่น ตอน Record ใส่ข้อมูล 5 เเถว
แต่พอ ด้วยมูลด้วย 5เเถว เหมือนเดิม ก็ถูกครับ แต่ พอเปลี่ยน เป็น 3 เเถว ก็ทำงานผิดแล้วครับ


Sub Macro12()
'
' Macro12 Macro
'
' Keyboard Shortcut: Ctrl+Shift+W
'
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Selection.End(xlDown).Select
Range("A6").Select
ActiveSheet.Paste
Selection.End(xlUp).Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Selection.End(xlDown).Select
Range("A11").Select
ActiveSheet.Paste
Selection.End(xlUp).Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Selection.End(xlDown).Select
Range("A21").Select
ActiveSheet.Paste
Selection.End(xlUp).Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Selection.End(xlDown).Select
Range("A41").Select
ActiveSheet.Paste
Selection.End(xlUp).Select
Range("B1").Select
Application.CutCopyMode = False
Range("A1").Select
End Sub

Re: Macros รัน ข้อมูลผิดไม่เหมือนตอน Record ครับ (มีตัวอย่างครับ)

Posted: Wed Jan 05, 2022 5:57 pm
by puriwutpokin
ควรว่างโค้ด ตามแบบวิธี การว่างโค้ดด้วยครับ
ตัวอย่างโค้ดครับ

Code: Select all

Sub Macro12()
For i = 1 To 15
Cells(i, 1) = ((i + 4) Mod 5) + 1
Next i
End Sub

Re: Macros รัน ข้อมูลผิดไม่เหมือนตอน Record ครับ (มีตัวอย่างครับ)

Posted: Thu Jan 06, 2022 8:29 am
by ballkoong

Code: Select all

Sub Macro12()
'
' Macro12 Macro
'
' Keyboard Shortcut: Ctrl+Shift+W
'
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Selection.End(xlDown).Select
Range("A6").Select
ActiveSheet.Paste
Selection.End(xlUp).Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Selection.End(xlDown).Select
Range("A11").Select
ActiveSheet.Paste
Selection.End(xlUp).Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Selection.End(xlDown).Select
Range("A21").Select
ActiveSheet.Paste
Selection.End(xlUp).Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Selection.End(xlDown).Select
Range("A41").Select
ActiveSheet.Paste
Selection.End(xlUp).Select
Range("B1").Select
Application.CutCopyMode = False
Range("A1").Select
End Sub

Re: Macros รัน ข้อมูลผิดไม่เหมือนตอน Record ครับ (มีตัวอย่างครับ)

Posted: Thu Jan 06, 2022 8:30 am
by ballkoong
puriwutpokin wrote: Wed Jan 05, 2022 5:57 pm ควรว่างโค้ด ตามแบบวิธี การว่างโค้ดด้วยครับ
ตัวอย่างโค้ดครับ

Code: Select all

Sub Macro12()
For i = 1 To 15
Cells(i, 1) = ((i + 4) Mod 5) + 1
Next i
End Sub
วาง Code ตามวิธีการ แล้วครับ

Re: Macros รัน ข้อมูลผิดไม่เหมือนตอน Record ครับ (มีตัวอย่างครับ)

Posted: Thu Jan 06, 2022 6:13 pm
by snasui
:D ตัวอย่างการปรับ Code ครับ

Code: Select all

Sub Macro12()
'
' Macro12 Macro
'
' Keyboard Shortcut: Ctrl+Shift+W
'
    Range("A1").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Selection.End(xlDown).Offset(1, 0).Select
    'Range("A6").Select
    ActiveSheet.Paste
    Selection.End(xlUp).Select
    Range(Selection, Selection.End(xlDown)).Select
    Application.CutCopyMode = False
    Selection.Copy
    Selection.End(xlDown).Offset(1, 0).Select
    'Range("A11").Select
    ActiveSheet.Paste
    Selection.End(xlUp).Select
    Range(Selection, Selection.End(xlDown)).Select
    Application.CutCopyMode = False
    Selection.Copy
    Selection.End(xlDown).Offset(1, 0).Select
    'Range("A21").Select
    ActiveSheet.Paste
    Selection.End(xlUp).Select
    Range(Selection, Selection.End(xlDown)).Select
    Application.CutCopyMode = False
    Selection.Copy
    Selection.End(xlDown).Offset(1, 0).Select
    'Range("A41").Select
    ActiveSheet.Paste
    Selection.End(xlUp).Select
    Range("B1").Select
    Application.CutCopyMode = False
    Range("A1").Select
End Sub