上面是我拥有的数据片段(在Sheet1中)。 我的任务是计算“ C”的插入次数,比如说从B到C(为此公式将写在Sheet2中)。我有代码,它工作正常。
但是我该怎么做才能基于在Sheet2的单元格A1中输入的特定UserID来获得计数。
例如:如果'Sheet2'!A1=3
,则应给出B到C表格第3行的计数:
(Result = Countif('Sheet1'!"B2:B4","C"))
希望我的解释是可以理解的。我需要一个不是这个宏的公式。
我尝试使用索引匹配获取行ID,但无法将其与CountIf结合使用。
VLOOKUP
和INDEX
MATCH
只能在我需要一个单元格值而不在同一行中使用多个值时使用。
Result = Countif('Sheet1'!"B2:B4","C")
答案 0 :(得分:0)
不是最优雅的公式,但是以下应该可以达到您想要的结果:
=COUNTIFS(Sheet1!A:A,Sheet2!A1,Sheet1!B:B,"C")+COUNTIFS(Sheet1!A:A,Sheet2!A1,Sheet1!C:C,"C")+COUNTIFS(Sheet1!A:A,Sheet2!A1,Sheet1!D:D,"C")+COUNTIFS(Sheet1!A:A,Sheet2!A1,Sheet1!E:E,"C")+COUNTIFS(Sheet1!A:A,Sheet2!A1,Sheet1!F:F,"C")
答案 1 :(得分:0)
如果您知道如何在excel中使用名称,则可以定义以下名称:
然后使用以下公式找到所需的计数:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_employee);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
realm = Realm.getDefaultInstance();
preferences = getSharedPreferences(PREFS_LOGIN, Context.MODE_PRIVATE);
recyclerView = findViewById(R.id.recyclerview);
singleItem = new ArrayList<>();
RealmResults<MdtmMandoranEmployeeDetail> resultEmployeeDetails = realm.where(MdtmMandoranEmployeeDetail.class)
.findAll().sort("employeename");
adapterListPemanen = new AdapterListPemanen(this, singleItem, this);
initVerticalRecycler();
for (int i = 0; i < 50; i++) {
DataPemanen data = realm.where(DataPemanen.class)
.equalTo("nik", resultEmployeeDetails.get(i).getEmployeeid())
.findFirst();
if (data == null) {
singleItem.add(new MdtmMandoranEmployeeDetail(resultEmployeeDetails.get(i).getMandoranemployeeid(),
resultEmployeeDetails.get(i).getEmployeeid(),
resultEmployeeDetails.get(i).getEmployeename()));
}
}
}
E/REALM_JNI: jni: ThrowingException 2, Out of range in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_OsResults.cpp line 102(requested: 0 valid: 0), .
Exception has been thrown: Out of range in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_OsResults.cpp line 102(requested: 0 valid: 0)
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.hpi.android.bkm, PID: 16623
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hpi.android.bkm/com.hpi.android.bkm.ui.main.input_pengiriman_hasil_panen.ListEmployeeActivity}: java.lang.ArrayIndexOutOfBoundsException: Out of range in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_OsResults.cpp line 102(requested: 0 valid: 0)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2805)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2883)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1613)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6523)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:857)
Caused by: java.lang.ArrayIndexOutOfBoundsException: Out of range in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_OsResults.cpp line 102(requested: 0 valid: 0)
at io.realm.internal.OsResults.nativeGetRow(Native Method)
at io.realm.internal.OsResults.getUncheckedRow(OsResults.java:325)
at io.realm.OrderedRealmCollectionImpl.get(OrderedRealmCollectionImpl.java:124)
at io.realm.RealmResults.get(RealmResults.java:62)
at com.hpi.android.bkm.ui.main.input_pengiriman_hasil_panen.ListEmployeeActivity.onCreate(ListEmployeeActivity.java:64)
at android.app.Activity.performCreate(Activity.java:7023)
at android.app.Activity.performCreate(Activity.java:7014)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2758)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2883)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1613)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6523)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:857)
是第二张工作表A1单元格中给定的用户ID 。您可以向下拖动此公式以应用到其余部分。
在下面的屏幕截图中,我使用了两组数据来测试结果。第一组与您的相同,并且A列中的用户ID是唯一的。在第二组数据中,有重复的用户ID,该公式仍会针对给定的用户ID查找C的出现,如突出显示。
SUMPRODUCT 有时类似于COUNTIFS,但功能更强大。
您可以阅读本文以了解有关SUMPRODUCT的更多信息:Excel SUMPRODUCT function with formula examples
干杯:)