需要跨范围制定公式仅对行中具有给定值的行进行操作u

时间:2017-05-04 10:01:18

标签: excel vba excel-vba

需要以下代码才能对列u中的值大于1的行执行操作。

Sub formulae_wfc()
    Range("v4:v200").Formula = "=T4*U4*0.01"
    Range("x4:x200").Formula = "=T4-V4"
    Range("aj4:aj200").Formula = "=IF(AK4=0,0, T4)"
    Range("am4:am200").Formula = "=AJ4*AK4*0.01"
    Range("at4:at200").Formula = "=(AP4-AQ4)*33.34%"
    Range("au4:au200").Formula = "=AT4+AS4"
    Range("av4:av200").Formula = "=AP4-AQ4-AT4"
    Range("aw4:aw200").Formula = "=T4-V4+AP4-AQ4-AS4-AT4"
End Sub

非常感谢

2 个答案:

答案 0 :(得分:0)

$timestamp=1275429600;

echo gmdate("d-m-Y", $timestamp);

使用cell.Offset(Rows,Col)使用相关单元格的位置查找给定单元格。

E.g。如果我们将cell_search等于A1,则cell_search.Offset(,1)会给我们B1。

E.g。如果我们将cell_search等于B2,则cell_search.Offset(-1,-1)将为我们提供A1。

如果cell_search已达到A1,您将使用:

Sub tommountain()
Dim rng As Range, cell_search As Range
Set rng = Intersect(Range("U:U"), ActiveSheet.UsedRange)
For Each cell_search In rng
If (cell_search.Value) > 1 Then
    'If the cell in range u:u is larger than 1, we execute the following
    'Use cell_search.Offset to find the cells in which you want your formulas
End If
Next cell_search
On Error Resume Next
End Sub

将给定的公式过去到(A + 1,1 + 1)=(B,2)= B2。

答案 1 :(得分:0)

For i = 4 To 200
If Range("u" & i).Value > 1 Then

Range("v" & i).FormulaR1C1 = "=RC[-1]*RC[-2]*0.01"
Range("x" & i).FormulaR1C1 = "=RC[-4]-RC[-2]"
Range("aj" & i).FormulaR1C1 = "=IF(RC[1]=0,0, RC[-16])"
Range("am" & i).FormulaR1C1 = "=RC[-3]*RC[-2]*0.01"
Range("at" & i).FormulaR1C1 = "=(RC[-4]-RC[-3])*33.34%"
Range("au" & i).FormulaR1C1 = "=RC[-1]+RC[-2]"
Range("av" & i).FormulaR1C1 = "=RC[-6]-RC[-5]-RC[-2]"
Range("aw" & i).FormulaR1C1 = "=RC[-29]-RC[-27]+RC[-7]-RC[-6]-RC[-4]-RC[-3]"
Else
End If
Next