I can run various SQL Queries to Sheet1 which return the expected results. The challenge I'm facing is that the "Last Cell" (F5>Special>Last Cell) keeps moving to the right on subsequent queries run.
Within the code I have cleared Sheet1 cells: Sheet1.Cell.Clearcontents, deleted Columns B:DZ and checked for query & existing connections (there are none).
Your thoughts are appreciated.
SQL and Last Cell
-
- GoldLounger
- Posts: 2628
- Joined: 26 Jan 2010, 16:31
- Location: Southern California
SQL and Last Cell
Regards,
John
John
-
- Administrator
- Posts: 78415
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- GoldLounger
- Posts: 2628
- Joined: 26 Jan 2010, 16:31
- Location: Southern California
Re: SQL and Last Cell
Hans,
I'm unable to post a sample workbook as there is a SQL database that the VBA code utilizes.
One thing that I observed is that the F5>Special>Last Cell returned cell address is not the same as the intersection of the last row/column used. If I save the file and run F5>Special>Last Cell again it returns the correct cell address.
I'm unable to post a sample workbook as there is a SQL database that the VBA code utilizes.
One thing that I observed is that the F5>Special>Last Cell returned cell address is not the same as the intersection of the last row/column used. If I save the file and run F5>Special>Last Cell again it returns the correct cell address.
Regards,
John
John
-
- Administrator
- Posts: 78415
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: SQL and Last Cell
You can reset the last cell in VBA by referring to the UsedRange property of the worksheet. For example:
Dim rng As Range
Set rng = ActiveSheet.UsedRange
You can refer to a specific sheet instead of to ActiveSheet, of course.
Dim rng As Range
Set rng = ActiveSheet.UsedRange
You can refer to a specific sheet instead of to ActiveSheet, of course.
Best wishes,
Hans
Hans
-
- GoldLounger
- Posts: 2628
- Joined: 26 Jan 2010, 16:31
- Location: Southern California