Hỏi về sự khác nhau giữa Formula2R1C1 và FormulaR1C1

Liên hệ QC

marcosheath479

Thành viên chính thức
Tham gia
23/2/22
Bài viết
53
Được thích
5
Chào mọi người,
Mình đang dùng Excel 2021 để ghi macro, trong ô có công thức Sumifs thì đoạn code ra như sau:
Mã:
Range("P3").Formula2R1C1 = _
        "=SUMIFS(NHAPXUAT,THANGNHAPXUAT,""1"",HTNX,""NHAP"",SP,DU_LIEU!RC[-5])"
Mọi người cho mình hỏi sự khác nhau giữa Formula2R1C1 và FormulaR1C1. Trong trường hợp hàm sumifs, mình thay Formula2R1C1 bằng FormulaR1C1 có gây lỗi không (vì mình sẽ gửi file này có nhiều người dùng, trong số đó có thể có các phiên bản Excel thấp hơn như 2016 chẳng hạn).

Cám ơn mọi người.
 
Bạn có thể hiểu là Formula2 hỗ trợ mảng động chỉ xuất hiện ở Excel 2021 và Excel 365, vì vậy cần thêm mã ràng buộc.
Tham khảo mã bên dưới:

JavaScript:
Function AppVersion() As Long
  Dim registryObject As Object
  Dim rootDirectory As String
  Dim keyPath As String
  Dim arrEntryNames As Variant
  Dim arrValueTypes As Variant
  Dim x As Long
  Select Case Val(Application.Version)
  Case Is = 16
    'Check for existence of Licensing key
    
    keyPath = "Software\Microsoft\Office\" & CStr(Application.Version) & "\Common\Licensing\LicensingNext"
    rootDirectory = "."
    Set registryObject = VBA.GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & rootDirectory & "\root\default:StdRegProv")
    registryObject.EnumValues &H80000001, keyPath, arrEntryNames, arrValueTypes
    On Error GoTo ErrorExit
    For x = 0 To UBound(arrEntryNames)
      If InStr(arrEntryNames(x), "365") > 0 Then
        AppVersion = 365
        Exit Function
      End If
      If InStr(arrEntryNames(x), "2019") > 0 Then
        If Application.Build >= 14332 Then
          'ProductCode: {90160000-000F-0000-1000-0000000FF1CE}
          'CalculationVersion:  191029
          AppVersion = 2021
        Else
          AppVersion = 2019
        End If
        Exit Function
      End If
    Next x
  Case Is = 15: AppVersion = 2013
  Case Is = 14: AppVersion = 2010
        'ProductCode: {91140000-0011-0000-1000-0000000FF1CE}
        'CalculationVersion:  145621
  Case Is = 12: AppVersion = 2007
  Case Else: AppVersion = 0
  End Select
  Exit Function
ErrorExit:
  'Version 16, but no licensing key. Must be Office 2016
  AppVersion = 2016
End Function
 
Upvote 0
Web KT
Back
Top Bottom