当部分中的所有值(名称范围为“ Allowances_Credits_Range”)均等于“ N / A”时,我们希望删除行的整个部分(名称范围为“ Remove_Allowances_Credits”)。
例如,当C161:C170中的每个值都等于“ N / A”时,我们希望删除行156:171。如何使用application.worksheetFunction count和countif完成此操作?
org.apache.hadoop.hive.ql.exec.mr.MapRedTask
at org.apache.hive.service.cli.operation.Operation.toSQLException(Operation.java:315)
at org.apache.hive.service.cli.operation.SQLOperation.runQuery(SQLOperation.java:156)
at org.apache.hive.service.cli.operation.SQLOperation.runInternal(SQLOperation.java:183)
at org.apache.hive.service.cli.operation.Operation.run(Operation.java:257)
at org.apache.hive.service.cli.session.HiveSessionImpl.executeStatementInternal(HiveSessionImpl.java:388)
at org.apache.hive.service.cli.session.HiveSessionImpl.executeStatement(HiveSessionImpl.java:369)
at sun.reflect.GeneratedMethodAccessor131.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.hive.service.cli.session.HiveSessionProxy.invoke(HiveSessionProxy.java:78)
at org.apache.hive.service.cli.session.HiveSessionProxy.access$000(HiveSessionProxy.java:36)
at org.apache.hive.service.cli.session.HiveSessionProxy$1.run(HiveSessionProxy.java:63)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:422)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1657)
at org.apache.hive.service.cli.session.HiveSessionProxy.invoke(HiveSessionProxy.java:59)
at com.sun.proxy.$Proxy22.executeStatement(Unknown Source)
at org.apache.hive.service.cli.CLIService.executeStatement(CLIService.java:261)
at org.apache.hive.service.cli.thrift.ThriftCLIService.ExecuteStatement(ThriftCLIService.java:486)
at org.apache.hive.service.cli.thrift.TCLIService$Processor$ExecuteStatement.getResult(TCLIService.java:1313)
at org.apache.hive.service.cli.thrift.TCLIService$Processor$ExecuteStatement.getResult(TCLIService.java:1298)
at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:39)
at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:39)
at org.apache.hive.service.auth.TSetIpAddressProcessor.process(TSetIpAddressProcessor.java:56)
at org.apache.thrift.server.TThreadPoolServer$WorkerProcess.run(TThreadPoolServer.java:285)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
我收到错误1004
If Application.WorksheetFunction.Count(Range("Allowances_Credits_Range")) = Application.WorksheetFunction.Count(Range("Allowances_Credits_Range", "n/a")) Then
Workbooks(PharmacyPricingGuarantees2).Sheets("Pharmacy Pricing Guarantees").Range("Remove_Allowances_Credits").Delete
End If
删除命名范围“ Remove_Allowances_Credits” 我收到错误1004
答案 0 :(得分:2)
不确定要达到的目标,所以我添加了几种不同的方法。
Sub Examples()
'Might need to change Workbook reference to PharmacyPricingGuarantees2?
Dim ws As Worksheet: Set ws = Thisworkbook.Sheets("Pharmacy Pricing Guarantees")
If ws.Range("Allowances_Credits_Range").Cells.Count = WorksheetFunction.CountIf(ws.Range("Allowances_Credits_Range"), "n/a") Then
ws.Range("Remove_Allowances_Credits").ClearContents '<-- Clear the values?
ws.Range("Remove_Allowances_Credits").EntireRow.Delete '<-- Delete the rows?
ThisWorkbook.Names("Remove_Allowances_Credits").Delete '<-- Delete the named range?
End If
End Sub
答案 1 :(得分:1)
尝试以下操作:
If Application.WorksheetFunction.COUNTA(Range("Allowances_Credits_Range")) =
Application.WorksheetFunction.COUNTIF(Range("Allowances_Credits_Range"), "#N/A")) Then
Workbooks(PharmacyPricingGuarantees2).Sheets("Pharmacy Pricing Guarantees").Range("Remove_Allowances_Credits").Delete
End If
首先,您想在第一部分中使用COUNTA
而不是COUNT
。 COUNT
仅计算数值。 COUNTA
计算所有非空值(包括#N / A)。
第二,您想使用COUNTIF
函数对值=#N / A进行计数。