how do i reference A1 using my long variable 'i'
![]()
Please Login or Register to view this content.
I want something like
but I need to get the column letter of cells(1, i) somehow.![]()
Please Login or Register to view this content.
how do i reference A1 using my long variable 'i'
![]()
Please Login or Register to view this content.
I want something like
but I need to get the column letter of cells(1, i) somehow.![]()
Please Login or Register to view this content.
![]()
Please Login or Register to view this content.
Regards,
Vandan
Wrong way round, there - A is the column, not the row:
![]()
Please Login or Register to view this content.
hi niko79542, there is a couple of ways for Range syntax:
1. Range("a1") - using variables: Range(x & y), where x = "a" and y=1
2. Range(Cells(i,n),cells(m,k)) where i,m - row identifier, n,k - columns
Noooo!!! Dont go away!!! Yes I understand these options, however my variable i is a number, and I cant use the
method. Because I get an error...![]()
Please Login or Register to view this content.
This here works for me...
This does not work for me...![]()
Please Login or Register to view this content.
...I figured I would save you guys the long winded reason as to why I am not using cells(1,i)...But here it is..![]()
Please Login or Register to view this content.
---------- Post added at 04:48 PM ---------- Previous post was at 04:46 PM ----------
Tchh... One really complicated way is
![]()
Please Login or Register to view this content.
Try this:
![]()
Please Login or Register to view this content.
Didn't get a change to try this out last night, but this is what I was looking for, thanks Andrew
So, I did scrounge up a solution. thanks again Andrew.
is the ..Cells in your code a shortcut? or did you just not bother typing out Range().
Not sure you ever revisit this thread again...but if you do =P.
nick
Inside a With block you use a period at the start of an object to show it's a child of the object named in the With.
So:
Means that you're referring to the Range A1 on sheet 1 of this workbook.![]()
Please Login or Register to view this content.
The same block of code without the period:
Means you're referring to range A1 on the active sheet, so the two blocks of code can return different results depending on which sheet is active when code is run.![]()
Please Login or Register to view this content.
This was what was causing you problems, when you were specifying:
All 4 references to Cells refer to objects on the active sheet, not necessarily on the sheets you're trying to copy from or paste to, and this was causing Excel problems. You were effectively saying, "Make a range on this sheet, from cell A to cell B on another sheet".![]()
Please Login or Register to view this content.
All my code did was precisely specify which cells I was referencing.
Does that make sense? It's a bit counter-intuitive, but such are the strange byways of Excel coding![]()
Ahh....That totally makes sense.
What I ended up doing was using Cells.Address to convert the column number to a letter, and then it was easy to go from there.
I thought I tried your way of referring to ranges using the period before the cell reference, but I got an error. I'll try it again now with your explanation in mind.![]()
Please Login or Register to view this content.
Nick
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks