Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 基于其他单元格内容插入数据_Excel_Vba - Fatal编程技术网

Excel 基于其他单元格内容插入数据

Excel 基于其他单元格内容插入数据,excel,vba,Excel,Vba,我对VBA略知一二,但似乎无法解决这个编程问题 我有一张表格,我想在其中规划任务结束前需要多少天。每个状态都等于天数,例如,如果文件处于挂起阶段,则总共需要180天才能完成。但我想要的是在每个阶段写下它需要的天数。比如说 状态写入范围E3:E160 如果范围内的单元格=挂起,则 偏移4列并写入20,偏移5列并写入35,偏移6列并写入50,偏移7列并写入25,偏移8列并写入15,偏移9列并写入15,最后偏移10列并写入20 但是,如果单元格位于range=“Planning”中,则偏移5列并写入3

我对VBA略知一二,但似乎无法解决这个编程问题

我有一张表格,我想在其中规划任务结束前需要多少天。每个状态都等于天数,例如,如果文件处于挂起阶段,则总共需要180天才能完成。但我想要的是在每个阶段写下它需要的天数。比如说

状态写入范围E3:E160

如果范围内的单元格=挂起,则 偏移4列并写入20,偏移5列并写入35,偏移6列并写入50,偏移7列并写入25,偏移8列并写入15,偏移9列并写入15,最后偏移10列并写入20

但是,如果单元格位于range=“Planning”中,则偏移5列并写入35,偏移6列并写入50,依此类推,直到偏移10列并写入20

目标是每个状态的tha,偏移量基于状态

希望这有帮助 我假设会有一个循环什么的,但我真的搞不懂

它还需要能够捕获范围内或范围外插入的任何新行

谢谢所有能帮助我的人

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim LastRow As Long
Dim i As Long
LastRow = Range("E" & Rows.Count).End(xlUp).Row

For i = 3 To LastRow

    If Range("E" & i).Value = "Pending" Then

    Range("I" & i).Value = "20" And Range("J" & i).Value = 35 And Range("K" & i).Value = 50 And Range("L" & i).Value = 25 And Range("M" & i).Value = 15 And Range("N" & i).Value = 15 And Range("O" & i).Value = 20

    ElseIf Range("E" & i).Value = "Planning" Then
    Range("J" & i).Value = 35 And Range("K" & i).Value = 50 And Range("L" & i).Value = 25 And Range("M" & i).Value = 15 And Range("N" & i).Value = 15 And Range("O" & i).Value = 20

    ElseIf Range("E" & i).Value = "Screening" Then
    Range("K" & i).Value = 50 And Range("L" & i).Value = 25 And Range("M" & i).Value = 15 And Range("N" & i).Value = 15 And Range("O" & i).Value = 20

    ElseIf Range("E" & i).Value = "Exam" Then
    Range("L" & i).Value = 25 And Range("M" & i).Value = 15 And Range("N" & i).Value = 15 And Range("O" & i).Value = 20

    ElseIf Range("E" & i).Value = "Interview" Then
    Range("M" & i).Value = 15 And Range("N" & i).Value = 15 And Range("O" & i).Value = 20

    ElseIf Range("E" & i).Value = "References" Then
    Range("N" & i).Value = 15 And Range("O" & i).Value = 20

    ElseIf Range("E" & i).Value = "Closing" Then
    Range("O" & i).Value = 20

    End If
Next i

End Sub

您需要去掉
Then
子句中的所有
语句。这是一个例子。你可以改变其余的。您可能还需要研究
案例选择
方法。

堆栈不是“代码为我”服务。如果您提供了您编写到目前为止的代码,其中包含一个特定的问题,我们可以进行故障排除,但您无法从零开始编写定制的解决方案。当然,很抱歉,到目前为止,我所编写的代码存在一个问题,即它“有效”,但它唯一能做的是在每个状态的第一个范围内写入0。希望你能帮助:-)我已经在我的问题中回答了代码。太棒了,我会尝试一下,并让你知道。谢谢你的帮助!:-)嘿,VALS,请考虑将它标记为接受。它对你和帮助你的人都有帮助:)
If Range("E" & i).Value = "Pending" Then

    Range("I" & i).Value = 20
    Range("J" & i).Value = 35
    Range("K" & i).Value = 50
    Range("L" & i).Value = 25
    Range("M" & i).Value = 15
    Range("N" & i).Value = 15
    Range("O" & i).Value = 20

ElseIf Range("E" & i).Value = "Planning" Then
    Range("J" & i).Value = 35
    Range("K" & i).Value = 50
    Range("L" & i).Value = 25
    Range("M" & i).Value = 15
    Range("N" & i).Value = 15
    Range("O" & i).Value = 20`