:D snasui.com ยินดีต้อนรับ :D
ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย :thup: สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ :arrow: ระบุ Version ของ Excel
:!: โปรดทราบ :!:
  1. กรุณาอ่านกฎการใช้บอร์ด (Forum rules) ในตำแหน่งด้านบนของแต่ละบอร์ด
  2. การสมัครสมาชิก การ Login การกู้คืนรหัสผ่าน
    1. สมัครสมาชิกดูขั้นตอนได้ที่ :arrow: สมัครสมาชิก
    2. Login เข้าระบบโดยคลิกปุ่ม Login ตรงมุมขวาบนของหน้านี้ :roll:
    3. การ Login ผ่าน Facebook ดูวิธีที่ :arrow: Login ผ่าน Facebook
    4. ลืมรหัสผ่านสามารถรับรหัสใหม่ได้ที่ :arrow: Reset รหัสผ่าน
  3. มีปัญหาการใช้งาน แจ้งผู้ดูแลระบบได้ที่ :arrow: ติดต่อผู้ดูแลระบบ
  4. กำหนดการตั้งค่าส่วนตัว เช่นตั้งค่าภาษาเป็นไทยหรืออังกฤษดูได้ที่ :arrow: ตั้งค่าส่วนตัว
  5. การตั้งและตอบกระทู้ดูได้ที่ :arrow: วิธีการตั้งและตอบกระทู้
  6. การจัดรูปแบบตัวอักษรด้วย bbcode ในช่องแสดงความคิดเห็นดูได้ที่ :arrow: จัดรูปแบบตัวอักษร
  7. กำหนดขนาดตัวอักษรใน Browser ดูได้ที่ :arrow: กำหนดขนาดตัวอักษรใน Browser

การวนลูป

ฟอรัมถาม-ตอบปัญหาการใช้งาน MS Excel and VBA
Forum rules
  1. ไม่อนุญาตให้ใช้ภาษาแชทในการถามและตอบปัญหา ไม่ใช้คำว่า "คับ" หรือ "อ่ะครับ" แทนคำว่า "ครับ" ไม่ใช้คำว่า "เด๋ว" แทนคำว่า "เดี๋ยว" เป็นต้น เนื่องจากเมื่อแปลเป็นภาษาต่างประเทศแล้วจะให้ความหมายผิดไปจากที่ควรจะเป็น
  2. ห้ามถามโดยระบุชื่อผู้ตอบและต้องตั้งชื่อกระทู้ให้สื่อถึงปัญหาที่จะถาม ไม่ตั้งชื่อว่า ช่วยด้วยครับ, มีปัญหามาปรึกษาครับ เป็นต้น
  3. กรุณาอธิบายปัญหาและระบุคำตอบที่ต้องการมาในกระทู้ด้วยเสมอถึงแม้จะอธิบายไว้ในไฟล์แนบแล้วก็ตาม ทั้งนี้เพื่ออำนวยความสะดวกแก่เพื่อนสมาชิกในการค้นหาข้อมูล
  4. กรุณาแนบไฟล์ตัวอย่างพร้อมแสดงคำตอบที่ถูกต้องมาในไฟล์ด้วยเพื่อให้ง่ายต่อการทำความเข้าใจและสะดวกต่อการตอบคำถาม (ขนาดไฟล์ไม่เกิน 500Kb ขนาดภาพไม่เกิน 800*600 Pixel) ไม่แนบเป็น Link มาจากแหล่งอื่นที่อาจจะถูกลบทิ้งไปโดยต้นทางในภายหลัง นอกจากนี้ไม่ควรแนบไฟล์ที่มีข้อมูลสำคัญอันก่อให้เกิดความเสียหายกับตนเองและผู้อื่น
  5. กรณีเป็นคำถามเกี่ยวกับ Programming เช่น VBA, VB.Net, C#, SQL ฯลฯ ต้องลองเขียนมาเองก่อนเสมอ ถามเฉพาะที่ติดปัญหา ระบุ Module, Procedure ที่ติดปัญหาให้ชัดเจน กรุณาโพสต์ Code ให้แสดงเป็น Code คือเปิดด้วย [code] และปิดด้วย [/code] ตัวอย่างเช่น [code]dim r as range[/code] เพื่อให้แตกต่างจากข้อความทั่วไป สะดวกในการอ่านและทดสอบ (คลิกเพื่อดูตัวอย่าง)
  6. กรุณาแจ้งผลการใช้งานเมื่อได้รับคำตอบว่าตรงกับความต้องการหรือไม่
aapichaya
Member
Member
Posts: 37
Joined: Wed Nov 08, 2017 7:55 am

การวนลูป

#1

Post by aapichaya »

อยากสอบถามโค้ดลูป for...Next ค่ะ พอดีเขียนเเล้วเเต่เหมือนว่าไม่ได้วนลูปจนจบไม่แน่ใจว่าเป็นเพราะว่าจำนวนรอบไม่เเน่นอนจึงทำให้ลูปไม่ทำงานหรือไม่

Code: Select all

Sub test()

 Dim x As Integer, NumRows As Integer
On Error Resume Next
  Application.ScreenUpdating = False
            NumRows = Range("C4", Range("C4").End(xlDown)).Rows.Count
                       Range("C4").Select
         
 For x = 3 To NumRows
                            
                     If Cells(x, 3).Value = "ECR Approval" Then
                   Cells(x, 47).Value = Cells(x, 5)
                   
       ElseIf Cells(x, 3).Value = "DCN Approval" Then
                    Cells(x, 47).Value = Cells(x, 5)
                    
       ElseIf Cells(x, 3).Value = "Drawing Release" Then
                    Cells(x, 47).Value = Cells(x, 5)
                    
       Else
                    Cells(x, 47).Value = Cells(x, 3)
          End If
          Cells(x, 3).Offset(1, 0).Select
          
 'x = x + 1
 Next x

 Application.ScreenUpdating = True
End Sub

You do not have the required permissions to view the files attached to this post.
eyepop99
Member
Member
Posts: 127
Joined: Fri Sep 01, 2017 3:19 pm
Excel Ver: 365,2019,2010

Re: การวนลูป

#2

Post by eyepop99 »

ปรับเป็น

Code: Select all

Sub test()

 Dim x As Integer, NumRows As Integer
On Error Resume Next
  Application.ScreenUpdating = False
  With Sheets("Sheet1")
            NumRows = .Range("B3", .Range("B" & Rows.Count).End(xlUp)).Rows.Count
    NumRows = NumRows + 2
 End With
        
 For x = 3 To NumRows
                            
                     If Cells(x, 3).Value = "ECR Approval" Then
                   Cells(x, 47).Value = Cells(x, 5)
                   
       ElseIf Cells(x, 3).Value = "DCN Approval" Then
                    Cells(x, 47).Value = Cells(x, 5)
                    
       ElseIf Cells(x, 3).Value = "Drawing Release" Then
                    Cells(x, 47).Value = Cells(x, 5)
                    
       Else
                    Cells(x, 47).Value = Cells(x, 3)
          End If
          Cells(x, 3).Offset(1, 0).Select
          
 'x = x + 1
 Next x

 Application.ScreenUpdating = True
End Sub


aapichaya
Member
Member
Posts: 37
Joined: Wed Nov 08, 2017 7:55 am

Re: การวนลูป

#3

Post by aapichaya »

ได้เเล้วค่ะ ขอบคุณมากค่ะ รบกวนดูอีกModule(Module1) ให้ด้วยได้ไหมคะ คิดว่าติดปัญหาตรง vlookup ค่ะ

Code: Select all

Sub test2()

Dim x As Integer, NumRows As Integer
Dim l As Integer
l = Worksheets("Sheet1").range("A3").End(xlDown).Row
On Error Resume Next
  Application.ScreenUpdating = False
  With Sheets("Sheet1")
            NumRows = .range("B3", .range("B" & Rows.Count).End(xlUp)).Rows.Count
    NumRows = NumRows + 2
 End With
        
 For x = 3 To NumRows
                            
                             If Cells(x, 3).Value = "ECR Approval" Then
                   Cells(x, 48).Value = Cells(x, 37)
                   
                             ElseIf Cells(x, 3).Value = "DCN Approval" Then
                    Cells(x, 48).Value = Cells(x, 37)
                    
                             ElseIf Cells(x, 3).Value = "Drawing Release" Then
        Cells(x, 48).Value = Cells(x, 37)
                    
                    ElseIf Cells(x, 37) = "" Then
                           If Cells(x, 3) = "ECR Approval" Then
            Cells(x, 48) = Application.WorksheetFunction.VLookup(Cells(x, 3), range("A3:AK" & l), 33, 0)
              End If
                              Else
                              Cells(x, 48).Value = Cells(x, 37)
                       
                              
          End If
  
          

 Next x

 Application.ScreenUpdating = True
End Sub
You do not have the required permissions to view the files attached to this post.
eyepop99
Member
Member
Posts: 127
Joined: Fri Sep 01, 2017 3:19 pm
Excel Ver: 365,2019,2010

Re: การวนลูป

#4

Post by eyepop99 »

เท่าที่ดู code นะครับ
-ไม่มีทางไหนเลย ที่จะเข้า If ที่เป็น Vlookup เนื่องจากว่า ที่ Cells(x,3) ไม่มีช่องใดว่าง เพราะฉะนั้นCode จะข้ามเงื่อนไข cells(x,37) ไป
-ส่วนการใช้ vlookup เงื่อนไขการใช้ vlookup จะดึงค่าที่เจอค่าแรกเสมอซึ่งทำให้ข้อมูลที่ดึงมาผิดพลาด ครับ
เพราะ เมื่อ vlookup เจอ จะนำค่าแรกมาเสมอ ถ้าต้องการจะใช้ vlookup ข้อมูลที่ lookup นั้นควรเป็นค่าไม่ซ้ำ ครับ

รบกวนเขียนเงื่อนไขที่ต้องการเพื่อช่วยแก้ปัญหาครับ
User avatar
puriwutpokin
Guru
Guru
Posts: 3713
Joined: Fri Jan 04, 2013 9:49 pm
Location: Bangkok
Excel Ver: MS.365

Re: การวนลูป

#5

Post by puriwutpokin »

ลองปรับเป็น

Code: Select all

Sub test2()
Dim x As Integer, NumRows As Integer
Dim l As Integer
l = Worksheets("Sheet1").range("A3").End(xlDown).Row
On Error Resume Next
  Application.ScreenUpdating = False
  With Sheets("Sheet1")
            NumRows = .range("B3", .range("B" & Rows.Count).End(xlUp)).Rows.Count
    NumRows = NumRows + 2
 End With
 For x = 3 To NumRows
                             If Cells(x, 3).Value = "ECR Approval" Then
                   Cells(x, 48).Value = Cells(x, 37)
                             ElseIf Cells(x, 3).Value = "DCN Approval" Then
                    Cells(x, 48).Value = Cells(x, 37)
                             ElseIf Cells(x, 3).Value = "Drawing Release" Then
        Cells(x, 48).Value = Cells(x, 37)
                    ElseIf Cells(x, 37) = "" Then
                           If Cells(x, 3) = "ECR Approval" Then
            Cells(x, 48) = Application.WorksheetFunction.VLookup(Cells(x, 3), range("C3:AK" & l), 35, 0)
              End If
                              Else
                              Cells(x, 48).Value = Cells(x, 37)
          End If
 Next x
 Application.ScreenUpdating = True
End Sub
:shock: :roll: :D
aapichaya
Member
Member
Posts: 37
Joined: Wed Nov 08, 2017 7:55 am

Re: การวนลูป

#6

Post by aapichaya »

เงื่อนไข คือต้องการดึงsend out date จาก parent enty ที่มีค่าเป็น ECR Approval,DCN Approval,Drawing Release มาวางในตัวที่มี ECR NO เดียวกันค่ะ (รบกวนดูไฟล์เเนบค่ะ)
You do not have the required permissions to view the files attached to this post.
User avatar
puriwutpokin
Guru
Guru
Posts: 3713
Joined: Fri Jan 04, 2013 9:49 pm
Location: Bangkok
Excel Ver: MS.365

Re: การวนลูป

#7

Post by puriwutpokin »

aapichaya wrote: Thu Jan 25, 2018 11:54 am เงื่อนไข คือต้องการดึงsend out date จาก parent enty ที่มีค่าเป็น ECR Approval,DCN Approval,Drawing Release มาวางในตัวที่มี ECR NO เดียวกันค่ะ (รบกวนดูไฟล์เเนบค่ะ)
ลองดูโค้ดนี้ครับ ผมงง กับ โค้ดเก่าและคำถามไม่ค่อยเข้าใจครับลองดูละกันครับ ว่าใช่ไหม

Code: Select all

Sub test2()
Dim x As Integer, NumRows As Integer
Dim l As Integer
l = Worksheets("Sheet1").Range("A3").End(xlDown).Row
On Error Resume Next
  Application.ScreenUpdating = False
  With Sheets("Sheet1")
            NumRows = .Range("B3", .Range("B" & Rows.Count).End(xlUp)).Rows.Count
    NumRows = NumRows + 2
 End With
 For x = 3 To NumRows
                             If Cells(x, 3).Value = "ECR Approval" Then
                   Cells(x, 48).Value = Cells(x, 37)
                             ElseIf Cells(x, 3).Value = "DCN Approval" Then
                    Cells(x, 48).Value = Cells(x, 37)
                             ElseIf Cells(x, 3).Value = "Drawing Release" Then
                   Cells(x, 48).Value = Cells(x, 37)
                   ' ElseIf Cells(x, 37) = "" Then
                         '  If Cells(x, 3) = "ECR Approval" Then
     '       Cells(x, 48) = Application.WorksheetFunction.VLookup(Cells(x, 3), Range("C3:AK" & l), 35, 0)
        '      End If
                             ' Else
                         '     Cells(x, 48).Value = Cells(x, 37)
          End If
 Next x
 Application.ScreenUpdating = True
End Sub
:shock: :roll: :D
eyepop99
Member
Member
Posts: 127
Joined: Fri Sep 01, 2017 3:19 pm
Excel Ver: 365,2019,2010

Re: การวนลูป

#8

Post by eyepop99 »

aapichaya wrote: Thu Jan 25, 2018 11:54 am เงื่อนไข คือต้องการดึงsend out date จาก parent enty ที่มีค่าเป็น ECR Approval,DCN Approval,Drawing Release มาวางในตัวที่มี ECR NO เดียวกันค่ะ (รบกวนดูไฟล์เเนบค่ะ)
แปลว่า ECR NO จะมีวันที่เดียวกันทั้งหมด ถูกต้องไหมครับ
aapichaya
Member
Member
Posts: 37
Joined: Wed Nov 08, 2017 7:55 am

Re: การวนลูป

#9

Post by aapichaya »

eyepop99 wrote: Thu Jan 25, 2018 1:38 pm
aapichaya wrote: Thu Jan 25, 2018 11:54 am เงื่อนไข คือต้องการดึงsend out date จาก parent enty ที่มีค่าเป็น ECR Approval,DCN Approval,Drawing Release มาวางในตัวที่มี ECR NO เดียวกันค่ะ (รบกวนดูไฟล์เเนบค่ะ)
แปลว่า ECR NO จะมีวันที่เดียวกันทั้งหมด ถูกต้องไหมครับ
ใช่ค่ะ ECR NO เดียวกันจะมีวันที่เดียวกันค่ะ
จากภาพ Row3และ 4มี ECR No เดียวกัน ดังนั้นในช่อง send out date 1 ในRow4ต้องเป็นวันที่ 11-Jan-18
เช่นเดียวกับRow5-7 ที่มี ECR No เดียวกันก็จะมีวันที่เดียวกันค่ะ
Image
User avatar
puriwutpokin
Guru
Guru
Posts: 3713
Joined: Fri Jan 04, 2013 9:49 pm
Location: Bangkok
Excel Ver: MS.365

Re: การวนลูป

#10

Post by puriwutpokin »

ลองดูครับว่าใช่ไหม

Code: Select all

Sub test2()
Dim x As Integer, NumRows As Integer
Dim l As Integer
l = Worksheets("Sheet1").Range("A3").End(xlDown).Row
On Error Resume Next
  Application.ScreenUpdating = False
  With Sheets("Sheet1")
            NumRows = .Range("B3", .Range("B" & Rows.Count).End(xlUp)).Rows.Count
    NumRows = NumRows + 2
 End With
 For x = 3 To NumRows
                             If Cells(x, 3).Value = "ECR Approval" Then
                   Cells(x, 48).Value = Cells(x, 37)
                             ElseIf Cells(x, 3).Value = "DCN Approval" Then
                    Cells(x, 48).Value = Cells(x, 37)
                             ElseIf Cells(x, 3).Value = "Drawing Release" Then
                   Cells(x, 48).Value = Cells(x, 37)
        ElseIf Cells(x, 3) <> "" And Cells(x, 37) = "" Then
            Cells(x, 48).Select
            Selection.FillDown
     End If
 Next x
 Application.ScreenUpdating = True
End Sub
:shock: :roll: :D
eyepop99
Member
Member
Posts: 127
Joined: Fri Sep 01, 2017 3:19 pm
Excel Ver: 365,2019,2010

Re: การวนลูป

#11

Post by eyepop99 »

ปรับตามนี้นะครับ น่าจะใช้ได้แล้ว ผมลองรันแล้ว ผ่าน

ปล. item ที่ 25และ26 ผลลัพธ์ไม่เหมือนตัวอย่างที่ให้มา เพราะว่า ERC NO นั้น VLOOKUp ตรวจพบ เท่ากับวันที่ 16-jan-18 เป็นตัวแรก
จะได้ผลลัพธ์เท่ากับ 16-jan-18
แต่ตัวอย่างผลลัพธ์ที่ได้ จะเท่ากับ 4-Jan-18

Code: Select all

Sub test()

 Dim x As Integer, NumRows As Integer
 Dim l As Integer
On Error Resume Next
  Application.ScreenUpdating = False
  With Sheets("Sheet1")
            NumRows = .Range("B3", .Range("B" & Rows.Count).End(xlUp)).Rows.Count
    NumRows = NumRows + 2
 End With
        
 For x = 3 To NumRows
                            
                     If Cells(x, 3).Value = "ECR Approval" Then
                   Cells(x, 47).Value = Cells(x, 5)
                   
       ElseIf Cells(x, 3).Value = "DCN Approval" Then
                    Cells(x, 47).Value = Cells(x, 5)
                    
       ElseIf Cells(x, 3).Value = "Drawing Release" Then
                    Cells(x, 47).Value = Cells(x, 5)
                    
       Else
                    Cells(x, 47).Value = Cells(x, 3)
          End If
          Cells(x, 3).Offset(1, 0).Select
          
 'x = x + 1
 Next x
l = Worksheets("Sheet1").Range("A2").End(xlDown).Row
For x = 3 To NumRows

With ActiveSheet

          .Cells(x, 48).Value = Application.IfError(Application.VLookup(.Cells(x, 47).Value, .Range("E:AK"), 33, 0), "")

End With
 Next x

 Application.ScreenUpdating = True
End Sub
User avatar
puriwutpokin
Guru
Guru
Posts: 3713
Joined: Fri Jan 04, 2013 9:49 pm
Location: Bangkok
Excel Ver: MS.365

Re: การวนลูป

#12

Post by puriwutpokin »

แก้ปัญหา Vlookup โดยวิธีนี้ดูครับ

Code: Select all

Sub test3()
Dim x As Integer, NumRows As Integer
On Error Resume Next
  Application.ScreenUpdating = False
  With Sheets("Sheet1")
            NumRows = .Range("B3", .Range("B" & Rows.Count).End(xlUp)).Rows.Count
    NumRows = NumRows + 2
 End With
 For x = 3 To NumRows
                    If Cells(x, 3).Value = "ECR Approval" Then
                   Cells(x, 47).Value = Cells(x, 5)
                   Cells(x, 48).Value = Cells(x, 37)
                   Cells(x, 48).Offset(1, 0).FillDown
       ElseIf Cells(x, 3).Value = "DCN Approval" Then
                    Cells(x, 47).Value = Cells(x, 5)
                    Cells(x, 48).Value = Cells(x, 37)
                    Cells(x, 48).Offset(1, 0).FillDown
       ElseIf Cells(x, 3).Value = "Drawing Release" Then
                    Cells(x, 47).Value = Cells(x, 5)
                    Cells(x, 48).Value = Cells(x, 37)
                    Cells(x, 48).Offset(1, 0).FillDown
       Else
                    Cells(x, 47).Value = Cells(x, 3)
             If Cells(x, 47).Value <> "" Then
                    Cells(x, 48).Offset(1, 0).FillDown
                    Else
                    Cells(x, 48).Value = ""
     End If
    End If
 Next x
 Application.ScreenUpdating = True
End Sub
:shock: :roll: :D
aapichaya
Member
Member
Posts: 37
Joined: Wed Nov 08, 2017 7:55 am

Re: การวนลูป

#13

Post by aapichaya »

puriwutpokin wrote: Thu Jan 25, 2018 2:33 pm ลองดูครับว่าใช่ไหม

Code: Select all

Sub test2()
Dim x As Integer, NumRows As Integer
Dim l As Integer
l = Worksheets("Sheet1").Range("A3").End(xlDown).Row
On Error Resume Next
  Application.ScreenUpdating = False
  With Sheets("Sheet1")
            NumRows = .Range("B3", .Range("B" & Rows.Count).End(xlUp)).Rows.Count
    NumRows = NumRows + 2
 End With
 For x = 3 To NumRows
                             If Cells(x, 3).Value = "ECR Approval" Then
                   Cells(x, 48).Value = Cells(x, 37)
                             ElseIf Cells(x, 3).Value = "DCN Approval" Then
                    Cells(x, 48).Value = Cells(x, 37)
                             ElseIf Cells(x, 3).Value = "Drawing Release" Then
                   Cells(x, 48).Value = Cells(x, 37)
        ElseIf Cells(x, 3) <> "" And Cells(x, 37) = "" Then
            Cells(x, 48).Select
            Selection.FillDown
     End If
 Next x
 Application.ScreenUpdating = True
End Sub
ขอบคุณมากค่ะ
aapichaya
Member
Member
Posts: 37
Joined: Wed Nov 08, 2017 7:55 am

Re: การวนลูป

#14

Post by aapichaya »

eyepop99 wrote: Thu Jan 25, 2018 5:02 pm ปรับตามนี้นะครับ น่าจะใช้ได้แล้ว ผมลองรันแล้ว ผ่าน

ปล. item ที่ 25และ26 ผลลัพธ์ไม่เหมือนตัวอย่างที่ให้มา เพราะว่า ERC NO นั้น VLOOKUp ตรวจพบ เท่ากับวันที่ 16-jan-18 เป็นตัวแรก
จะได้ผลลัพธ์เท่ากับ 16-jan-18
แต่ตัวอย่างผลลัพธ์ที่ได้ จะเท่ากับ 4-Jan-18

Code: Select all

Sub test()

 Dim x As Integer, NumRows As Integer
 Dim l As Integer
On Error Resume Next
  Application.ScreenUpdating = False
  With Sheets("Sheet1")
            NumRows = .Range("B3", .Range("B" & Rows.Count).End(xlUp)).Rows.Count
    NumRows = NumRows + 2
 End With
        
 For x = 3 To NumRows
                            
                     If Cells(x, 3).Value = "ECR Approval" Then
                   Cells(x, 47).Value = Cells(x, 5)
                   
       ElseIf Cells(x, 3).Value = "DCN Approval" Then
                    Cells(x, 47).Value = Cells(x, 5)
                    
       ElseIf Cells(x, 3).Value = "Drawing Release" Then
                    Cells(x, 47).Value = Cells(x, 5)
                    
       Else
                    Cells(x, 47).Value = Cells(x, 3)
          End If
          Cells(x, 3).Offset(1, 0).Select
          
 'x = x + 1
 Next x
l = Worksheets("Sheet1").Range("A2").End(xlDown).Row
For x = 3 To NumRows

With ActiveSheet

          .Cells(x, 48).Value = Application.IfError(Application.VLookup(.Cells(x, 47).Value, .Range("E:AK"), 33, 0), "")

End With
 Next x

 Application.ScreenUpdating = True
End Sub
โอเคค่ะ ขอบคุณมากค่ะ
aapichaya
Member
Member
Posts: 37
Joined: Wed Nov 08, 2017 7:55 am

Re: การวนลูป

#15

Post by aapichaya »

puriwutpokin wrote: Thu Jan 25, 2018 7:39 pm แก้ปัญหา Vlookup โดยวิธีนี้ดูครับ

Code: Select all

Sub test3()
Dim x As Integer, NumRows As Integer
On Error Resume Next
  Application.ScreenUpdating = False
  With Sheets("Sheet1")
            NumRows = .Range("B3", .Range("B" & Rows.Count).End(xlUp)).Rows.Count
    NumRows = NumRows + 2
 End With
 For x = 3 To NumRows
                    If Cells(x, 3).Value = "ECR Approval" Then
                   Cells(x, 47).Value = Cells(x, 5)
                   Cells(x, 48).Value = Cells(x, 37)
                   Cells(x, 48).Offset(1, 0).FillDown
       ElseIf Cells(x, 3).Value = "DCN Approval" Then
                    Cells(x, 47).Value = Cells(x, 5)
                    Cells(x, 48).Value = Cells(x, 37)
                    Cells(x, 48).Offset(1, 0).FillDown
       ElseIf Cells(x, 3).Value = "Drawing Release" Then
                    Cells(x, 47).Value = Cells(x, 5)
                    Cells(x, 48).Value = Cells(x, 37)
                    Cells(x, 48).Offset(1, 0).FillDown
       Else
                    Cells(x, 47).Value = Cells(x, 3)
             If Cells(x, 47).Value <> "" Then
                    Cells(x, 48).Offset(1, 0).FillDown
                    Else
                    Cells(x, 48).Value = ""
     End If
    End If
 Next x
 Application.ScreenUpdating = True
End Sub
ขอบคุณมากค่ะ
Post Reply