VBA代码-Excel 选中单元格区域并复制

2025-04-07 09:57:36

1、说明:1、将从数据库中取到的数据放到AG4单元格;2、选中AG4单元格的区域,并复制;3、将复制的单元格区域转置并放到H2单元格;4、清除AG4单元格区域;

2、代码: Cells(4, "AG").CopyFromRecordset cnn.Execute(sq1) Range("AG4").CurrentRegion.Select Selection.Copy Cells(2, "H").Select Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:=False, Transpose:=True Range("AG4").CurrentRegion.ClearContents

3、解释:1、sq1是SQL语句; Cells(4, "AG").CopyFromRecordset cnn.Execute(sq1) 'cnn.execute(sq1)是执行数据库命令。整个语句是将执行数据库命令得到的结果放到AG4单元格

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢