- ·上一篇:wpsexcel怎么做门牌号
- ·下一篇:怎么在excel图中加散点图
vba怎么写两个excel表格
1.Excel中VBA如何操作两个表的数据
Public Sub 复制数据()
Dim sh1, sh2 As Range
Set sh1 = Sheets("biao1").Range("A1:A10000")
Set sh2 = Sheets("biao2").Range("D1:D10000")
Sheets("biao3").Range("a1") = Sheets("biao1").Range("A1")
han = 0
For x = 1 To 100
sj = Sheets("biao1").Cells(x, 1)
If han > 0 Then
For y = 1 To han
sj1 = Sheets("biao3").Cells(y, 1)
If sj1 = sj Then
cf = True
Exit For
Else
cf = False
End If
Next y
End If
If cf = False Then
han = han + 1
Sheets("biao3").Cells(han, 1) = Sheets("biao1").Cells(x, 1)
End If
Next x
han = han - 1
For x = 1 To 100
sj = Sheets("biao2").Cells(x, 1)
If han > 1 Then
For y = 1 To han
sj1 = Sheets("biao3").Cells(y, 1)
If sj1 = sj Then
cf = True
Exit For
Else
cf = False
End If
Next y
End If
If cf = False Then
han = han + 1
Sheets("biao3").Cells(han, 1) = Sheets("biao2").Cells(x, 1)
End If
Next x
End Sub
哈哈,学习了。UsedRange.Rows.Count:表中有数据的最后一行的行号。
2.vba如何将两个EXCEL工作簿 1工作簿单元格的内容写到2工作簿的指
最后一句应该是引用对应名称工作簿吧。具体如下:
Sub 引用()
n = 1 '项目总数,即汇总表A列行数
For i = 1 To n
shname = Sheets("汇总表").Range("A" & i).Value 'Ai的值,即工作簿名
Set ssh = Sheets(shname) '引用工作簿名对应工作簿
MsgBox ssh.Range("A1").Value, 0, "OK" '显示该对应工作簿A1的值,测试用,可删除
'ssh里的其他操作
Next
End Sub
