ต้องการให้เก็บ rate ตามวันที่เลือกเข้าที่ไฟล์ AVG_rate
เข่น วันที่ 22/5/23 อยู่ที่ cell N1 ที่ Currency "USD " ที่ cell F9 ให้ไปวางไว้ที่ F22 ที่ file AVG_rate ที่ sheet AVG_USD
เข่น วันที่ 22/5/23 อยู่ที่ cell N1 ที่ Currency "SGD " ที่ cell F15 ให้ไปวางไว้ที่ F22 ที่ file AVG_rate ที่ sheet AVG_SGD
แต่พอรันแล้วติด Debud ค่ะ ต้องปรับ code vba ยังไงคะ
Code: Select all
Sub Run_rate()
Dim dayOfMth As Variant, dataAll As Range
Dim rngCur As Range, r As Range
With Workbooks("Year 2023.xlsx").Worksheets("AVG_SGD")
Set dataAll = .Range("B3:M33")
End With
With Workbooks("Main.xlsm").Worksheets("Rate_BOT")
dayOfMth = VBA.Split(VBA.Mid(.Range("A1"), VBA.InStr(.Range("A1"), "as of") + 6), " ")
Set rngCur = .Range("B:B").Find("SGD").Offset(0, 3)
End With
For Each r In dataAll
If r.Parent.Cells(r.Row, "A").Value = "Day " & dayOfMth(0) And _
Application.Text(r.Parent.Cells(2, r.Column), "[$- ]mmmm") = dayOfMth(1) Then
r.Value = rngCur.Value
Exit For
End If
Next r
'Dim dayOfMth As Variant, dataAll As Range
'Dim rngCur As Range, r As Range
With Workbooks("Year 2023.xlsx").Worksheets("AVG_USD")
Set dataAll = .Range("B3:M33")
End With
With Workbooks("Main.xlsm").Worksheets("Rate_BOT")
dayOfMth = VBA.Split(VBA.Mid(.Range("A1"), VBA.InStr(.Range("A1"), "as of") + 6), " ")
Set rngCur = .Range("B:B").Find("USD").Offset(0, 3)
End With
For Each r In dataAll
If r.Parent.Cells(r.Row, "A").Value = "Day " & dayOfMth(0) And _
Application.Text(r.Parent.Cells(2, r.Column), "[$- ]mmmm") = dayOfMth(1) Then
r.Value = rngCur.Value
Exit For
End If
Next r
Windows("Year 2023.xlsx").Activate
End Sub
You do not have the required permissions to view the files attached to this post.