Sub update_excel()
Dim x As Integer
Dim y As Integer
Dim str_do As String
Dim int_id As Integer
Dim str_name As String
Dim str_sta As String
Dim str_desc As String
Dim obj As Object
Set obj = CreateObject("Excel.Application")
Dim wb As Workbook
Set wb = obj.Workbooks.Open("C:\Users\Sunny\Desktop\TEST.xlsx")
Dim sheet As Worksheet
Set sheet = wb.Sheets("G")
Set sht = ThisWorkbook.Worksheets("Sheet2")
x = 5
y = 2
Do While sht.Cells(x, 2) <> ""
str_do = sht.Cells(x, 1)
int_id = sht.Cells(x, 2)
str_name = sht.Cells(x, 3)
str_sta = sht.Cells(x, 4)
str_desc = sht.Cells(x, 5)
If str_do <> "N" Then
m_x = int_id + 1
sheet.Cells(m_x, y).Value = str_name
sheet.Cells(m_x, y + 1).Value = str_sta
sheet.Cells(m_x, y + 2).Value = str_desc
End If
x = x + 1
Loop
wb.Close savechanges:=True
obj.Quit
Set wb = Nothing
Set obj = Nothing
End Sub
Read Another Excel - way. 1
最新推荐文章于 2024-09-10 10:56:36 发布