将变量添加到另一个变量vba中

时间:2015-06-22 19:43:39

标签: excel vba excel-vba

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os, glob, shutil, time, datetime
path = glob.glob('/home/piratinha/*')
now  = time.time()
now_str = datetime.datetime.fromtimestamp(now).strftime('%d-%m-%Y %H:%M:%S')
print now_str
for f in path:
    if os.stat(f).st_mtime < now - (6 * 30 * 86400):
        if os.path.isfile(f):
            print "Removendo", f
            os.remove(f)
            print "Arquivo Removido"
        else:
            print "Removendo", f
            shutil.rmtree(f)
            print "Pasta Removida"
else:
    print   "Todos os arquivos e pastas são mais novos do que 6 meses."

print now_str

这些名称右侧的5列中有值。我需要添加它们,而不在行之间添加任何数字。

我写的最后一部分错了吗?它出现为0.但是参考单元格中有明显的数据。

1 个答案:

答案 0 :(得分:1)

我无法看到代码有任何问题,只要您的文字在列 C 中,且值在列 H

我也冒昧地重写代码以使其更清晰:

Sub test()
Dim x As Long
Dim y As Long
Dim TotalValue As Double

TotalValue = 0
y = 3

For x = 600 To 1 Step -1
    Select Case Cells(x, y).Value
        Case "CD Sector Average", "CS Sector Average", _
                "E Sector Average", "F Sector Average", _
                "H Sector Average", "I Sector Average", _
                "IT Sector Average", "M Sector Average", _
                "T Sector Average", "U Sector Average"
            TotalValue = TotalValue + Cells(x, y + 5).Value
        Case "Total Portfolio"
            Cells(x, y + 5).Value = TotalValue
            TotalValue = 0
    End Select
Next x

End Sub