×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

VBA code to referance range for Column

VBA code to referance range for Column

VBA code to referance range for Column

(OP)
Hello,

I am looking to export data from an access query to an excel workbook. I can do it for cell ranges using the following code:

CODE -->

ExcelSheet.Range("H144").FormulaR1C1 = Me.[Parts Number] 

However, I need to export data into a column range and when I tried using the code below its not working right.

CODE -->

ExcelSheet.Range("F17:F105").Columns.Value= Me.[Cost] 

What am I doing wrong?

Thanks,

Lavender

RE: VBA code to referance range for Column

Hi,

CODE

ExcelSheet.Range("F17").Value= Me.[Cost] 

It will begin at F17 and fill downward.

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

RE: VBA code to referance range for Column

Actually, I'd query your Access table from Excel via Data > Get external data > From Access...

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

RE: VBA code to referance range for Column

(OP)
Hi SkipVought,

Thanks for the help but code

CODE -->

ExcelSheet.Range("F17").Value= Me.[Cost] 
is only writing the first number of the cost column in F17 and repeating it all the way down. Would a loop next funtion help with this problem?

Thanks,
Lavender

RE: VBA code to referance range for Column

If you can get your data into a recordset then you can drop it into Excel with:

Range.CopyFromRecordset

Copies the contents of an ADO or DAO Recordset object onto a worksheet, beginning at the upper-left corner of the specified range.

So if your result set only has one column then your output will be one column.

e.g.

CODE --> VBA

ExcelSheet.Range("F17").CopyFromRecordset YourRecordSet 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close