sql - Select Dynamic Table Range In Excel Using VBA -
i trying select dynamic table - can figure out copy/pasting part of script, can't figure out how select table.
the table dynamic in terms of both number of rows , number of columns. because lone workbook need usable different business units, calling different sql server tables. user puts inputs in sheet1, refreshes connection, , table returned in sheet2.
here snippets, including working , broken portion:
'variable designations dim rowcount string dim columncount string dim sheetref1 string dim sheetref2 string dim rangeselect1 string dim rangeselect2 string rowcount = cells(rows.count, 1).end(xlup).row columncount = cells(1, columns.count).end(xltoleft).column sheetref1 = "sheet1" sheetref2 = "sheet2" rangeselect1 = "a2:a" & rowcount rangeselect2 = "a1:" & columncount & rowcount '<--broken 'copy column populated rows sheets(sheetref1).range(rangeselect1).copy '<--working 'copy table populated rows , columns sheets(sheetref2).range(rangeselect2).copy '<--broken so here rangeselect2 = "a1:" & columncount & rowcount trying return a1:z10 or a1:f3000 - dynamic range (by way, a1 static). attempt columncount return "z" or "f" or whatever last column letter is, while rowcount (hopefully) returns last row number.
hopefully makes sense. gladly answer further questions, , appreciate advice/help.
your rangeselect2 = "a1:" & columncount & rowcount isn't working because columncount , rowcount coming numbers indicating row , column. if want translate columncount , rowcount a1 address (e.g. column 2 , row 5 b5), can use cells(rowcount, columncount).address, returns absolute reference coordinate.
rangeselect2 = "a1:" & cells(rowcount, columncount).address should work you're trying here.
Comments
Post a Comment