VBS:Excel中的条件列填充

时间:2017-10-26 10:05:29

标签: excel vbscript

我是VB Scripting的新手。我试图在这里编写一个代码,它将插入三个新列,然后在其中一个现有列中检查条件(在代码中指定),并根据值填充其中一个新列。但是在这里我遇到了多个错误。任何人都可以指导我朝着正确的方向帮助我吗?

P.S-工作代码如下。答案同样在评论中。

     Const xlToRight = -4161
const xlColumns = &H2 
const xlLinear = -4132 
const xlDay = 1

Set objExcel = CreateObject("Excel.Application")
    objExcel.Application.Visible = True

Set objWorkbook = objExcel.Workbooks.Open("C:\Temp\Qualysrep.xlsx")
Set objSheet =objWorkbook.Sheets("Sheet1")

Set objRange = objExcel.Range("F1").EntireColumn
    objRange.Insert(xlShiftToRight)

Set objRange = objExcel.Range("G1").EntireColumn
    objRange.Insert(xlShiftToRight)

Set objRange = objExcel.Range("H1").EntireColumn
    objRange.Insert(xlShiftToRight)

objsheet.Cells(11,6) = "DeviceType"
objsheet.Cells(11,7) = "Domain"
objsheet.Cells(11,8) = "Status in AD"


Dim DeviceType 
Dim OS 
Dim lastrowrange 
Dim i 
lastrowrange = objSheet.Range("A65536").End(-4162).Row
Set DeviceType = objsheet.Range("F1",objsheet.Cells(lastrowrange, 22))
Set OS = objsheet.Range("J1",objsheet.Cells(lastrowrange, 22))
For i = 1 to lastrowrange
    If OS.Cells(i,1).Value = "Windows 2012 Standard" Then
        DeviceType.Cells(i,1).Value = "Server"
        Else
        DeviceType.Cells(i,1).Value = "Not a Server"
    End If
Next 


objWorkbook.Close True
objExcel.Quit

0 个答案:

没有答案