ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Cells V Range (https://www.excelbanter.com/excel-programming/283757-cells-v-range.html)

CJ[_3_]

Cells V Range
 
Hi

I have an interesting problem. I am populating an Excel
template from an Access database using
..Range(.Cells(8, 9), .Cells(8, 10)).select
..Range(.Cells(8, 9), .Cells(8, 10)).CopyFromRecordset rs

All appears to work fine. When I open the Excel sheet, it
doesn't seem like any of the data has been populated. BUT
if I go to my immediate window, then cells(8,9) shows me
the value that should have been pasted in, but range("L9")
shows me the old value that should have been overwritten

I was under the impression that Cells and Range were a
synonymous way of refering to the same thing???

Any help would be appreciated.



patrick molloy

Cells V Range
 

Don't select or activate the range...

set WS = Worksheets(somesheetnameornumber)
With WS

..Cells(8, 9).CopyFromRecordset rs

End With

---- assuming that there are records in the RS!!

and yes, you can also use
..Range("L8").CopyFromRecordset rs


You are correct Range and cells are sysnonymous
Range(Range("B2"),Range("E7"))
Range(Range("B2"),cells(7,"E"))
Range(Range("B2"),cells(7,5))
Range(Cells(2,2),cells(7,"E"))
Range(cells(7,"E"),Range("B2"))

Patrick Molloy
Microsoft Excel MVP



-----Original Message-----
Hi

I have an interesting problem. I am populating an Excel
template from an Access database using
..Range(.Cells(8, 9), .Cells(8, 10)).select
..Range(.Cells(8, 9), .Cells(8, 10)).CopyFromRecordset rs

All appears to work fine. When I open the Excel sheet,

it
doesn't seem like any of the data has been populated.

BUT
if I go to my immediate window, then cells(8,9) shows me
the value that should have been pasted in, but range

("L9")
shows me the old value that should have been overwritten

I was under the impression that Cells and Range were a
synonymous way of refering to the same thing???

Any help would be appreciated.


.


Bill Manville

Cells V Range
 
Cj wrote:
if I go to my immediate window, then cells(8,9) shows me
the value that should have been pasted in, but range("L9")
shows me the old value that should have been overwritten


Cells(8, 9) is cell "I8" - row 8, column 9
Not surprising that L9 was not changed!

Bill Manville
MVP - Microsoft Excel, Oxford, England
No email replies please - reply in newsgroup


David Turner

Cells V Range
 
Patrick Molloy wrote

You are correct Range and cells are sysnonymous
Range(Range("B2"),Range("E7"))


OT, but can I reference this one this way?
Range("B2,E7")

--
David


All times are GMT +1. The time now is 03:34 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com