View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Auric__ Auric__ is offline
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