|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 hehex 于 2012-10-31 17:06 编辑
For 没有next 是你把循环都改了,可能是你更改的时候误把红色代码下面的那句Next 给删除了。
加回去就好了。
'L列求和
If Cells(r, 1) <> "" Then Cells(r, 12) = Worksheets("" & y).Cells(hang, 40) * 1.5 * Cells(r, 6)
'M列求和
If Cells(r, 1) <> "" Then Cells(r, 13) = Worksheets("" & y).Cells(hang, 40) * 11 * 2 * Cells(r, 7)
'N列求和
If Cells(r, 1) <> "" Then Cells(r, 14) = Worksheets("" & y).Cells(hang, 40) * 11 * 3 * Cells(r, 8)
是用我的语句把原来的这些代码替换掉,起到这些语句得出的结果四舍五入的效果,其他的保持原样不动。
还有上面的错误,end with 没有with 也和我给你替换的语句无关,是你误删了其他语句了。
我把你上面的代码复制下来,然后改了你说的红色代码,没动其他的,不行你再复制回去看看吧:
- Sub 查找()
- y = WorksheetFunction.Substitute([p2], "~", "至")
- With Sheets("" & y).Range("A5:AU20")
- a = [a65536].End(xlUp).Row
- For r = 4 To a
- m = Array(4, 5, 7, 8, 9, 11, 15)
- For n = 0 To 6
- c = m(n)
- Set rng0 = .Find(what:=Cells(r, 1))
- If Not rng0 Is Nothing Then
- hang = rng0.Row
- End If
- Set rng1 = .Find(what:=Cells(3, c), lookat:=xlPart)
- If Not rng1 Is Nothing Then
- lie = rng1.Column
- End If
- '("D3:E3","G3:I3","K3","O3")的求和
- If Cells(r, 1) <> "" Then Cells(r, c) = Worksheets("" & y).Cells(hang, lie)
- Next
- Next
- End With
- Call 另1
- End Sub
- Sub 另1()
- y = WorksheetFunction.Substitute([p2], "~", "至")
- With Sheets("" & y).Range("A5:AU20")
- a = [a65536].End(xlUp).Row
- For r = 4 To a
- Set rng0 = .Find(what:=Cells(r, 1))
- If Not rng0 Is Nothing Then
- hang = rng0.Row
- End If
- 'F4求和
- t = Worksheets("" & y).Cells(hang, 45)
- If t <> 0 Then
- o = (Cells(r, 4) * 3) - ((Cells(r, 3) - t - Cells(r, 4)) * 8)
- Else
- o = (Cells(r, 4) * 3) - ((Cells(r, 3) - Cells(r, 4)) * 8)
- End If
- If Cells(r, 1) <> "" Then Cells(r, 6) = o
- Next
- End With
- Call 另2
- End Sub
- Sub 另2()
- y = WorksheetFunction.Substitute([p2], "~", "至")
- With Sheets("" & y).Range("A5:AU20")
- a = [a65536].End(xlUp).Row
- For r = 4 To a
- Set rng0 = .Find(what:=Cells(r, 1))
- If Not rng0 Is Nothing Then
- hang = rng0.Row
- End If
- 'J列求和
- If Cells(r, 1) <> "" Then Cells(r, 10) = Worksheets("" & y).Cells(hang, 41) * Cells(r, 5)
- 'L列求和
- If Cells(r, 1) <> "" Then
- Cells(r, 12) = Worksheets("" & y).Cells(hang, 40) * 1.5 * Cells(r, 6)
- Cells(r, 12).Value = WorksheetFunction.Round(Cells(r, 12).Value, 2)
- End If
- 'M列求和
- If Cells(r, 1) <> "" Then
- Cells(r, 13) = Worksheets("" & y).Cells(hang, 40) * 11 * 2 * Cells(r, 7)
- Cells(r, 13).Value = WorksheetFunction.Round(Cells(r, 13).Value, 2)
- End If
- 'N列求和
- If Cells(r, 1) <> "" Then
- Cells(r, 14) = Worksheets("" & y).Cells(hang, 40) * 11 * 3 * Cells(r, 8)
- Cells(r, 14).Value = WorksheetFunction.Round(Cells(r, 14).Value, 2)
- End If
- Next
- End With
- End Sub
复制代码
|
|