excel 在凌乱的工作簿中使用MAXIFS

2ic8powd  于 2023-03-13  发布在  其他
关注(0)|答案(1)|浏览(121)

这是long via脚本的最后一步。我尝试使用列C中的条件和列E中的值填充列H中的最大值。问题是列E中的最后一行可以从50到Excel可以处理的任何值(大约最大Excel行数/50)。有什么提示吗?谢谢。(是的,我知道代码很草率。这是从效率低得多的早期版本创建的。)

sFile = ThisWorkbook.Name
  sFileName = sPathName & sFile
  Set wbSource = Workbooks.Open(sFileName)
  Set wbTarget = Workbooks.Open(sFileName)
  Set wsTarget = Worksheets("Priority Values calculated")
  wsTarget.Range("G2").Copy
  wsTarget.Range("G2").PasteSpecial (xlPasteValues)
  wsTarget.Range("H1") = "Seats In Each State"
  
  With wbTarget
  
    wsTarget.Range("H2") = 1
    wsTarget.Range("H2") = MAXIFS($E$2:$E$&lLastRow,!$C$2:$C$&lLastRow, C2)
    
  End With
8ftvxx2r

8ftvxx2r1#

将公式写入动态单列区域

sFileName = sPathName & ThisWorkbook.Name
Set wbTarget = Workbooks.Open(sFileName)
Set wsTarget = wbTarget.Worksheets("Priority Values calculated")

With wsTarget
    .Range("G2").Value = .Range("G2").Value ' copy/paste values
    .Range("H1").Value = "Seats In Each State"
    '.Range("H2").Value = 1 ' ???
    .Range("H2:H" & lLastRow).Formula _
        = "=MAXIFS($E$2:$E$" & lLastRow & ",$C$2:$C$" & lLastRow & ",C2)"
End With

相关问题