0
让我开始说我对于使用excel和VBA非常新,但对C++有一定的经验。用另一个工作簿中的信息更新Excel表格
的情况:
我试图更新一个表与另一个工作簿中的数据。源文件按照每个新工作单被赋予一列的方式组织。随着更多门票进入,更多列被创建,并且关于该门票的各种信息被垂直列出。
基本上我试图做的是保持与相同的票号作为第一个更新的第二个文件,但有不同的格式:
Basic example of the two sheets
这里是我到目前为止,虽然对于一个什么样的基本思想很粗糙,我想代码做的事:
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
我意识到这可能与错误/基本错误百出,但如果任何人都可以伸出援助之手,这将是伟大的!
太谢谢你了!我肯定会试试这个! –