Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 542
Default VBA to find difference in cell locations

Is it possible to find the difference between cell locations. Such as if I
am on cell E1 and pick another cell H1, I would like to know the difference
between the locations. In this case there are 2 cells between E1 and H1.

I am writting a code that needs to know the difference between the cell
location, I just don't know what the VBA looks like for something like this.

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default VBA to find difference in cell locations

You don't need VBA for this.

You could use:
=column(h1)-column(e1)
and if you wanted the row difference:
=row(h1)-row(e1)

If you wanted to ignore the end points, you could just subtract 1 from the
formula.
=column(h1)-column(e1)-1

But I'm not sure I do that.

How many columns are between H1 and H2?

In code, you could use:

Dim Cell1 as range
dim Cell2 as range

with worksheets("SomeSheetNameHere")
set cell1 = .range("h1")
set cell2 = .range("e1")
end with

msgbox cell1.column - cell2.column '-1 'if you want.



James wrote:

Is it possible to find the difference between cell locations. Such as if I
am on cell E1 and pick another cell H1, I would like to know the difference
between the locations. In this case there are 2 cells between E1 and H1.

I am writting a code that needs to know the difference between the cell
location, I just don't know what the VBA looks like for something like this.

Thanks


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 542
Default VBA to find difference in cell locations

Dave,
That was to easy, I guess I tried to get to complicated the other day.
Thank you again.

"Dave Peterson" wrote:

You don't need VBA for this.

You could use:
=column(h1)-column(e1)
and if you wanted the row difference:
=row(h1)-row(e1)

If you wanted to ignore the end points, you could just subtract 1 from the
formula.
=column(h1)-column(e1)-1

But I'm not sure I do that.

How many columns are between H1 and H2?

In code, you could use:

Dim Cell1 as range
dim Cell2 as range

with worksheets("SomeSheetNameHere")
set cell1 = .range("h1")
set cell2 = .range("e1")
end with

msgbox cell1.column - cell2.column '-1 'if you want.



James wrote:

Is it possible to find the difference between cell locations. Such as if I
am on cell E1 and pick another cell H1, I would like to know the difference
between the locations. In this case there are 2 cells between E1 and H1.

I am writting a code that needs to know the difference between the cell
location, I just don't know what the VBA looks like for something like this.

Thanks


--

Dave Peterson
.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculate the difference between two row locations? CxT Excel Discussion (Misc queries) 2 April 4th 23 02:23 PM
How to reference cell that changes locations. ArrDubbSmith Excel Worksheet Functions 1 December 4th 09 01:24 PM
Excel:Swap cell contents-including cell groups-betwen 2 locations Rob R Excel Discussion (Misc queries) 0 February 6th 08 11:13 PM
Cell locations DL9998 Excel Discussion (Misc queries) 2 December 6th 07 06:19 PM
Try to find the difference by percentage between 2 cell totals chedd via OfficeKB.com New Users to Excel 1 June 8th 06 09:40 AM


All times are GMT +1. The time now is 02:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"