让我首先说我对使用 excel 和 VBA 非常陌生,但是对 c++ 有一些经验。
情况:
我正在尝试使用在另一个工作簿中找到的数据更新一个工作表。源文件的组织方式使每个新工作票都有一个列。随着越来越多的工单进来,就会创建更多的列,并且垂直列出有关该工单的各种信息。
基本上我想要做的是使用与第一个相同的票号更新第二个文件,但格式不同:
这是我到目前为止所拥有的,虽然对于我想要代码做什么的基本概念来说非常粗糙:
Sub Update_Click() //Button to update destination file
Workbooks.open("C:\Documents\mysourcefile.xlsm")
dim i,j as integer
i=4 //starting column of source file where first ticket is stored
j=2 //starting column of destination file where first ticket is stored
while worksheets("mysourcesheet").Value(i,2)<>0 //all work has customer, but
//may not have a ticket
//number
if Worksheets("mysourcesheet").value(i,1) = 0 Then
i=i+1 //some columns in the source are blank due to canceled orders
//this is to go to the next column
else
if Worksheets("mysourcesheet").value(i,1)=Worksheets("mydestsheet").value(j,1)
then
i=i+1
j-j+2 //go onto the next if already updated
//J+2 to account for formatting of the cells
Else
Worksheets("mysourcesheet").value(i,1)=Worksheets("mydestsheet").value(j,1)
Worksheets("mysourcesheet").value(i,2)=Worksheets("mydestsheet").value(j,2)
Worksheets("mysourcesheet").value(i,3)=Worksheets("mydestsheet").value(j,4)
Worksheets("mysourcesheet").value(i,4)=Worksheets("mydestsheet").value(j,5)
//copy the data
i=i+1
j=j+2
end if
end if
end sub
我意识到这可能充满了错误/基本错误,但如果有人能伸出援助之手,那就太好了!