Find Last Row in DataSet Excel VBA -


i'm trying data import find last row of dataset , paste row of data sql server blank row @ end of data set.

this code have, when running code import data on last row, not next blank row after last row

sub runimport() on error goto err: cnnstr = "provider=sqloledb; " & _             "data source=myserver; " & _             "initial catalog=mydb;" & _             "user id=user;" & _             "password=pwd;" & _             "trusted_connection=no" set cnn = new adodb.connection application.screenupdating = false cnn.open cnnstr set rs = new adodb.recordset sqry = "select * mytable" rs.cursorlocation = aduseclient rs.open sqry, cnn, adopendynamic, adlockoptimistic, adcmdtext application.screenupdating = false sheet1.range("b5").select range(selection, selection.end(xldown)).select activecell.offset(1, 0).copyfromrecordset rs rs.close set rs = nothing cnn.close set cnn = nothing exit sub err: msgbox "the following error has occured-" & vbcrlf & vbcrlf & vba.error, vbcritical, "myspreadsheet" msgbox vba.err end sub 

i imagine have put in wrong around

sheet1.range("b5").select range(selection, selection.end(xldown)).select activecell.offset(1, 0).copyfromrecordset rs 

what need put right?

i found simpler answer looking for.

range("a1").end(xldown).offset(1, 0).select 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -