Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default comparing two columns in vba

Hello, I need help again. In excel sheet, I can compare two cells with "exact" command.However in vba, I need to use "exact" command in a loop, and I have to assign column names as variables. For example;

For j=1 To 10
For i = 1 To 100
Sheets("IS1").Cells(i, 4 + 3 * (j - 2)) = "=EXACT(C1;C2 )"
Next
Next

works fine but It compares just 1st and 2nd columns. However, I want to compare for j'th column with j+1'th column. How can I do this. I will be very glad. Thanks a lot.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default comparing two columns in vba

oercim wrote:

Hello, I need help again. In excel sheet, I can compare two cells with
"exact" command.However in vba, I need to use "exact" command in a loop,
and I have to assign column names as variables. For example;

For j=1 To 10
For i = 1 To 100
Sheets("IS1").Cells(i, 4 + 3 * (j - 2)) = "=EXACT(C1;C2 )"
Next
Next

works fine but It compares just 1st and 2nd columns. However, I want to
compare for j'th column with j+1'th column. How can I do this. I will be
very glad.


Somewhat like this:

jOffset = 64
For j = 1 To 10
For i = 1 To 100
Sheets("IS1").Cells(i, 4 + 3 * (j - 2)) = "=EXACT(" & Chr(j + _
jOffset) & "1," & Chr(j + jOffset + 1) & "2)"
Next
Next

Set jOffset equal to ASC(UCASE(starting column letter)) - 1. jOffset = 64
will start at column A, jOffset = 65 will start at column B, etc.

--
- being bi-polar must suck
- well yes and no
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default comparing two columns in vba

Auric__ wrote:

oercim wrote:

Hello, I need help again. In excel sheet, I can compare two cells with
"exact" command.However in vba, I need to use "exact" command in a
loop, and I have to assign column names as variables. For example;

For j=1 To 10
For i = 1 To 100
Sheets("IS1").Cells(i, 4 + 3 * (j - 2)) = "=EXACT(C1;C2 )"
Next
Next

works fine but It compares just 1st and 2nd columns. However, I want to
compare for j'th column with j+1'th column. How can I do this. I will
be very glad.


Somewhat like this:

jOffset = 64
For j = 1 To 10
For i = 1 To 100
Sheets("IS1").Cells(i, 4 + 3 * (j - 2)) = "=EXACT(" & Chr(j + _
jOffset) & "1," & Chr(j + jOffset + 1) &
"2)"
Next
Next

Set jOffset equal to ASC(UCASE(starting column letter)) - 1. jOffset =
64 will start at column A, jOffset = 65 will start at column B, etc.


Ah, hell. My code doesn't account for columns beyond Z. This does...

For j = 1 To 100
For i = 1 To 10
Sheets("IS1").Cells(i, 4 + 3 * (j - 2)).Formula = "=EXACT(" & _
Mid(Cells(i, j).Address, 2, InStr(2, Cells(i, j).Address, _
"$") - 2) & "1," & Mid(Cells(i, j + 1).Address, 2, InStr(2, _
Cells(i, j + 1).Address, "$") - 2) & "2)"
Next
Next

Note that the need for jOffset has been removed. This code is somewhat more
complex, but it doesn't need any tomfoolery to get the column, just grabs it
straight from the Address property.

--
Things heard on Hell's P.A. system:
Attention, will the owner of a Pinto, license plate number...
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
Comparing columns Dave T Excel Worksheet Functions 1 May 23rd 09 10:27 AM
Comparing two columns VMI Excel Programming 1 August 27th 08 07:31 PM
comparing two columns mouhammmmmmmad Excel Discussion (Misc queries) 1 January 19th 07 10:46 PM
Comparing two columns of information with 2 new columns of informa cbuck Excel Discussion (Misc queries) 1 January 16th 07 09:49 PM
comparing 2 columns PLPE Excel Programming 18 June 2nd 05 12:14 PM


All times are GMT +1. The time now is 10:14 AM.

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"