在excel表中怎样编写一个vb小程序实现从一个sheet的单元格的内容拷贝到另一个sheet的单元各种?请大家帮帮忙,多谢哦!我又改写了一下小程序,但实现不了i=4时将单元格的数据复制啊?为什么?是循环语句错了吗?能帮忙改一下吗?代码如下:
Private Sub CommandButton1_Click()'Set xlbooks = Workbooks.Open("C:\Documents and Settings\Administrator\桌面\Li Ling\新建文件夹\GUI080710.xls") Dim Sheet1 As Worksheet
Dim Sheet2 As Worksheet Dim a, b, i Set Sheet1 = Sheets("CompanyList")
Set Sheet2 = Sheets("International")
i = 3
a = Sheet1.Cells(2, i)
b = Sheet2.Cells(9, 3)
Do While b > a Or b < a
Loop
Sheet2.Cells(9, 3).Value = Sheet1.Cells(2, i).Value
Sheet2.Cells(10, 3).Value = Sheet1.Cells(4, i).Value
Sheet2.Cells(11, 3).Value = Sheet1.Cells(5, i).Value
Sheet2.Cells(12, 3).Value = Sheet1.Cells(6, i).Value
Sheet2.Cells(13, 3).Value = Sheet1.Cells(7, i).Value
Sheet2.Cells(14, 3).Value = Sheet1.Cells(8, i).Value
Sheet2.Cells(21, 3).Value = Sheet1.Cells(10, i).Value
Sheet2.Cells(22, 3).Value = Sheet1.Cells(11, i).Value
Sheet2.Cells(23, 3).Value = Sheet1.Cells(9, i).Value
i = i + 1
End Sub急!请大家帮帮忙!!!!!!
Private Sub CommandButton1_Click()'Set xlbooks = Workbooks.Open("C:\Documents and Settings\Administrator\桌面\Li Ling\新建文件夹\GUI080710.xls") Dim Sheet1 As Worksheet
Dim Sheet2 As Worksheet Dim a, b, i Set Sheet1 = Sheets("CompanyList")
Set Sheet2 = Sheets("International")
i = 3
a = Sheet1.Cells(2, i)
b = Sheet2.Cells(9, 3)
Do While b > a Or b < a
Loop
Sheet2.Cells(9, 3).Value = Sheet1.Cells(2, i).Value
Sheet2.Cells(10, 3).Value = Sheet1.Cells(4, i).Value
Sheet2.Cells(11, 3).Value = Sheet1.Cells(5, i).Value
Sheet2.Cells(12, 3).Value = Sheet1.Cells(6, i).Value
Sheet2.Cells(13, 3).Value = Sheet1.Cells(7, i).Value
Sheet2.Cells(14, 3).Value = Sheet1.Cells(8, i).Value
Sheet2.Cells(21, 3).Value = Sheet1.Cells(10, i).Value
Sheet2.Cells(22, 3).Value = Sheet1.Cells(11, i).Value
Sheet2.Cells(23, 3).Value = Sheet1.Cells(9, i).Value
i = i + 1
End Sub急!请大家帮帮忙!!!!!!
解决方案 »
- 数据库中获得的字符串,如何让它变成一个控件
- vb6 Collection对象有长度??
- [求助]如何用VB封装连接字符串
- 直接打印mshflexgrid里的内容,如何实现较简单
- 高分求救.在线等???在Excel中如何把新建的工作表,放在某一工作表之后,而不是之前?????
- &&&&&&&&&&&&& HELP ME &&&&&&&&&&&&&&&
- 100分答谢!如何屏蔽WebBrowser控件的上下滚动,和左右滚动功能?
- 我参照一篇文章用MSFlexGrid结合text控件实现在MSFlexGrid表格里改数据,单不知道怎样把修改后的数据写到数据库里!急救!!!
- VB里new一对象后,当不再用到此对象时,是否也要象VC一样delete掉,如果是,用什么方法?
- 请教一个数据处理的问题,高手们帮帮忙
- asp如何发送url再获取返回页里的数据
- VB远程访问互联网MSSQL数据库?架构?
啊,这几天都急疯了唉!!!!!!!!1
不知道代码在做什么。
Dim Sheet2 As Worksheet
Dim a, b, i Set Sheet1 = xlbooks.Sheets("CompanyList")
Set Sheet2 = xlbooks.Sheets("International")
i = 3
a = Sheet1.Cells(2, i)
b = Sheet2.Cells(9, 3)
Do While b > a Or b < a
Sheet2.Cells(9, 3).Value = Sheet1.Cells(2, i).Value
Sheet2.Cells(10, 3).Value = Sheet1.Cells(4, i).Value
Sheet2.Cells(11, 3).Value = Sheet1.Cells(5, i).Value
Sheet2.Cells(12, 3).Value = Sheet1.Cells(6, i).Value
Sheet2.Cells(13, 3).Value = Sheet1.Cells(7, i).Value
Sheet2.Cells(14, 3).Value = Sheet1.Cells(8, i).Value
Sheet2.Cells(21, 3).Value = Sheet1.Cells(10, i).Value
Sheet2.Cells(22, 3).Value = Sheet1.Cells(11, i).Value
Sheet2.Cells(23, 3).Value = Sheet1.Cells(9, i).Value
i = i + 1 a = Sheet1.Cells(2, i)
Loop
End Sub
Do While b > a Or b < a
Sheet2.Cells(9, 3).Value = Sheet1.Cells(2, i).Value
Sheet2.Cells(10, 3).Value = Sheet1.Cells(4, i).Value
Sheet2.Cells(11, 3).Value = Sheet1.Cells(5, i).Value
Sheet2.Cells(12, 3).Value = Sheet1.Cells(6, i).Value
Sheet2.Cells(13, 3).Value = Sheet1.Cells(7, i).Value
Sheet2.Cells(14, 3).Value = Sheet1.Cells(8, i).Value
Sheet2.Cells(21, 3).Value = Sheet1.Cells(10, i).Value
Sheet2.Cells(22, 3).Value = Sheet1.Cells(11, i).Value
Sheet2.Cells(23, 3).Value = Sheet1.Cells(9, i).Value
i = i + 1
if i=10 then exit do'这里要加一句退出语句,条件自已加,否则会死循环
a = Sheet1.Cells(2, i)
Loop
当相等的时候,复制相等的那列下面的内容到指定位置
我的代码:
Private Sub cmdCopy_Click()
Dim ColiumnIndex As Long
Dim Sheet1 As Worksheet
Dim Sheet2 As Worksheet
Set Sheet1 = Sheets("CompanyList")
Set Sheet2 = Sheets("International")
ColiumnIndex = FindColumnIndex(Sheets("International").Cells(9, 3))
If ColiumnIndex = 0 Then
MsgBox "没有找到此客户资料!"
Exit Sub
End If
Sheet2.Cells(10, 3) = Sheet1.Cells(4, ColiumnIndex)
Sheet2.Cells(11, 3) = Sheet1.Cells(5, ColiumnIndex)
Sheet2.Cells(12, 3) = Sheet1.Cells(6, ColiumnIndex)
Sheet2.Cells(13, 3) = Sheet1.Cells(7, ColiumnIndex)
Sheet2.Cells(14, 3) = Sheet1.Cells(8, ColiumnIndex)
Sheet2.Cells(21, 3) = Sheet1.Cells(10, ColiumnIndex)
Sheet2.Cells(22, 3) = Sheet1.Cells(11, ColiumnIndex) Sheet2.Cells(23, 3) = Sheet1.Cells(9, ColiumnIndex)
End Sub
Private Function FindColumnIndex(ByVal strBuy As String) As Long
Dim I As Long
Dim oSheet As Worksheet
Set oSheet = Sheets("CompanyList")
I = 3
While Len(oSheet.Cells(2, I)) > 0
If oSheet.Cells(2, I) = strBuy Then
FindColumnIndex = I
Exit Function
End If
I = I + 1
Wend
End Function