VBA突出显示行

时间:2016-06-27 19:10:50

标签: excel vba excel-vba

我正在尝试创建一个迭代excel文档的代码。我希望宏根据我正在检查的单元格左侧的值突出显示所有行。这就是我想说的,但在代码中无法正常使用。

def get_par(filename_or_pard):

    # automatically search for the path

    Path = GetPathOsmosisPth()
    f = open(Path,'r')

    TheLines = f.readlines()
    Path = TheLines[0][0:-1] + '/osmosis/'
    f.close()

    # Get the name of the path to the data
    ThePath = locate_dir('GeneralParameters',Path)
    Thepdata = ThePath.split('GeneralParameters')[0]      #(line 216 - This line gives error) 

    # check if we do not have provided an external data path
    DataDir = CheckInputDataDirectory()
    #DataDir = 'Data_CS'
    if DataDir is None:
        pdata = Thepdata
    else:
        pdata = os.path.join(Path,DataDir)

    # search for the file

    if isstring(filename_or_pard):
        # myprintv("isstring: ", filename_or_pard)
        # creating the dictionary
        ThePath = locate(filename_or_pard,pdata)
        f = ThePath + os.path.sep + filename_or_pard
        pard = create_par_structure(f)

        # creating the class par_struct
        par = par_struct(pard)

        # store the filename with the parameters in the par structure

        par.TheFilename = filename_or_pard
    else:
        # myprint2v("not isstring: ", filename_or_pard, type(filename_or_pard))
        # the dictionary is provided as input
        pard = filename_or_pard

        # creating the class par_struct
        if isdict(pard):
            par = par_struct(pard)
            par._FromStringToTrueType()
        else:
            par = pard

    # if parameters.txt, set the path_data

    if hasattr(par,'path_data'):
        par.path_data = pdata
        par.root_path = Path
        # myprintv("pdata: ", par.path_data)

    if hasattr(par,'path_packages'):
        par.path_packages = os.path.join(Path,par.path_packages)

    # returning the result
    return par

请帮助,谢谢。

1 个答案:

答案 0 :(得分:1)

虽然我无法确定,但我相信你想翻译你的伪代码

for x = 4 to 3918
    if Instr(cells(x, 2), "LW") then
        numToFind = cells(x, 1)
        for y = 4 to 3918
            if cells(y, 1) = numToFind then
                cells(y, 1).entirerow.Interior.ColorIndex = 4
            end if
        next y
    end if
next x

我读你是对吗?