Using Row Count in Range Selection

riggsd

Registered User.
Local time
Today, 16:27
Joined
Dec 2, 2003
Messages
28
I have some VBA code that extracts data from my Access database, opens a new Excel workbook, adds column headers, and then puts the extracted data into the spreadsheet.

As part of this process, I use a counter to move from row to row.

I need to use the row count to select a range of cells to apply borders and set the print area since every time the data is extracted the range changes.

MyExcel.Range("A3:A+CurrentRow").Select
ActiveSheet.PageSetup.PrintArea = $A$3:$AM$CurrentRow

How do I put the row number in the range using the CurrentRow figure? :confused:

One other thing, how do I put the current date in the file name when I save the file via the VBA code?

For example, a report saved today would be:

Total_List_of_PPLs_02-11-04.xls

but a file saved tomorrow will need to have 02_12_04 there instead.

...

By the way, I don't have "CurrentRow" in my code as I haven't written the set print area section yet. It's just to show my problem.

Thanks in advance.
 
Last edited:
dar,

Code:
MyExcel.Range("A3:A+" & CurrentRow).Select
or
MyExcel.Range("A3:A+" & Trim(Str(CurrentRow))).Select


Me.FileName = "Total_List_of_PPLs_" + Format(Date, "mm-dd-yy") & "02-11-04.xls"

Wayne
 
Thanks Wayne,

but wouldn't

Me.FileName = "Total_List_of_PPLs_" + Format(Date, "mm-dd-yy") & "02-11-04.xls"

put "02-11-04" at the end of the filename? That is the date that needs to change daily.
 
dar,

Sorry, I just left your "hard-coded" value in.

Code:
Me.FileName = "Total_List_of_PPLs_" & Format(Date, "mm-dd-yy") & ".xls"

AND I've been working with SQL Server lately (no "+")

Wayne
 

Users who are viewing this thread

Back
Top Bottom