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单元格