麻烦与Interior.ColorIndex和单元格样式相加

时间:2019-05-21 13:14:46

标签: excel vba

我无法通过Interior.ColorIndex和Cell Style来计算单元格。我正在使用偏移量检查另一列,并使用For循环检查每个单元格。我认为我的If语句有问题。这不行吗,因为循环会检查通过所有If语句运行的每个单元格?

  public function createuserinfo(Request $request)
{
    $user = Auth::user();

    $userupdate = $user->update([
        'status' => '1'
    ]);

    $infocreate = Personal::create([
        'user_id' => $user->id,
        'first_name' => $request->first_name,
        'last_name' => $request->last_name,
        'email' => $request->email,
        'password' => $request->password,
        'address' => $request->address,
        'zipcode' => $request->zipcode,
        'city' => $request->city,
        'phone_number' => $request->phone_number,
        'ss_number' => $request->ss_number,
        'document_number' => $request->document_number,
        'license_number' => $request->license_number,
        'expiration_date' => $request->expiration_date,
        'employer' => $request->employer,
        'jobtitle' => $request->jobtitle,
        'contract' => $request->contract,
        'start_date' => $request->start_date,
        'general_practitioner' => $request->general_practitioner,
        'dentist' => $request->dentist,
        'health_insurance' => $request->health_insurance,
        'contact_one_name' => $request->contact_one_name,
        'contact_one_relation' => $request->contact_one_relation,
        'contact_one_address' => $request->contact_one_address,
        'contact_one_zipcode' => $request->contact_one_zipcode,
        'contact_one_city' => $request->contact_one_city,
        'contact_one_phone_number' => $request->contact_one_phone_number,
        'contact_two_name' => $request->contact_two_name,
        'contact_two_relation' => $request->contact_two_relation,
        'contact_two_address' => $request->contact_two_address,
        'contact_two_zipcode' => $request->contact_two_zipcode,
        'contact_two_city' => $request->contact_two_city,
        'contact_two_phone_number' => $request->contact_two_phone_number
    ]);

    return $userupdate . $infocreate . redirect()->route('users.details');
}

就结果而言,我已经对所有31个单元格进行了计数,但它们并没有进行排序。根据我的更改,所有31个单元格都归为一个变量。

CaffeineCacheManager

2 个答案:

答案 0 :(得分:1)

循环遍历rng中的单元格,但是If都基于ActiveCell,它是工作表中选定的单元格,与cell没有任何共同之处。而是使用cell.Offset...

答案 1 :(得分:0)

刚刚找到了我自己的问题的答案,但谢谢您的回答。 我将ActiveCell偏移量更改为寻找范围(“ C”和cell.Row)。

Sub Totals()
Dim rng As Range, cell As Range
Dim Supertotal As Long
Dim Subtotal As Long
Dim Ptotal As Long
Set rng = Range("F2:F32")
Supertotal = 0
Subtotal = 0
Ptotal = 0
For Each cell In rng
    If Range("C" & cell.Row).Interior.ColorIndex = 6 Then
        Supertotal = Supertotal + 1
    ElseIf Range("C" & cell.Row).Style = "Note" Then
        Subtotal = Subtotal + 1
    Else
        Ptotal = Ptotal + 1
    End If
Next cell
MsgBox "The Total Number of SuperTests is " & Supertotal
MsgBox "The Total Number of SubTests is " & Subtotal
MsgBox "The Total Number of Procedure Tests is " & Ptotal

End Sub