Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
tom tom is offline
external usenet poster
 
Posts: 570
Default How to write a for loop to get the range between a ,b columns


Dim x,y As Integer

NumRows = Range("B3", Range("B3").End(xlDown)).Rows.Count

Range("C2").Select


For x = 1 To NumRows

For y= cells(A).value to cells(B).value
'which code we have to write for comparing a1,b1 are equal or not
ActiveCell.FormulaR1C1 = "=Sum(RC[-1]+1)"

ActiveCell.Offset(x, 0).FillDown
Next
Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default How to write a for loop to get the range between a ,b columns


This compares the cell in column A to the cell in column B on the same row.
If there is a match, then the message box will identify which row.


Sub rngCompare()
lr = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = ActiveSheet.Range("A2:A" & lr)
For Each c In rng
If c.Value = c.Offset(0,1).Value Then
MsgBox "Bingo on row " & c.Row
End If
Next
End Sub




"tom" wrote in message
...
Dim x,y As Integer

NumRows = Range("B3", Range("B3").End(xlDown)).Rows.Count

Range("C2").Select


For x = 1 To NumRows

For y= cells(A).value to cells(B).value
'which code we have to write for comparing a1,b1 are equal or not
ActiveCell.FormulaR1C1 = "=Sum(RC[-1]+1)"

ActiveCell.Offset(x, 0).FillDown
Next
Next



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default How to write a for loop to get the range between a ,b columns


The below code marks a "Mismatch" in ColC

Dim lngRow as Long, lngLastRow as Long
lngLastRow = ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row
For lngRow = 1 To lngLastRow
If Range("A" & lngRow)< Range("B" & lngRow) Then
Range("C" & lngRow) = "Mismatch"
End If
Next

If this post helps click Yes
---------------
Jacob Skaria


"tom" wrote:

Dim x,y As Integer

NumRows = Range("B3", Range("B3").End(xlDown)).Rows.Count

Range("C2").Select


For x = 1 To NumRows

For y= cells(A).value to cells(B).value
'which code we have to write for comparing a1,b1 are equal or not
ActiveCell.FormulaR1C1 = "=Sum(RC[-1]+1)"

ActiveCell.Offset(x, 0).FillDown
Next
Next

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default How to write a for loop to get the range between a ,b columns


I'm not clear what you're trying to achieve here. Do you just want to see
where items in column A don't match the item in the same row in column B?
why were you using the SUM function in column C?

for checking mismatches try this:-

With Range(Range("B3"), Range("B3").End(xlDown)).Offset(, 1)
.FormulaR1C1 = "=IF(RC1<RC2,""MISMATCH"","""")"
End With

"tom" wrote in message
...
Dim x,y As Integer

NumRows = Range("B3", Range("B3").End(xlDown)).Rows.Count

Range("C2").Select


For x = 1 To NumRows

For y= cells(A).value to cells(B).value
'which code we have to write for comparing a1,b1 are equal or not
ActiveCell.FormulaR1C1 = "=Sum(RC[-1]+1)"

ActiveCell.Offset(x, 0).FillDown
Next
Next


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default How to write a for loop to get the range between a ,b columns

the question is very similar to Sam's "How to program this" on 25th June at
18:03.
please check the many replies already given.

"Patrick Molloy" wrote in message
...
I'm not clear what you're trying to achieve here. Do you just want to see
where items in column A don't match the item in the same row in column B?
why were you using the SUM function in column C?

for checking mismatches try this:-

With Range(Range("B3"), Range("B3").End(xlDown)).Offset(, 1)
.FormulaR1C1 = "=IF(RC1<RC2,""MISMATCH"","""")"
End With

"tom" wrote in message
...
Dim x,y As Integer

NumRows = Range("B3", Range("B3").End(xlDown)).Rows.Count

Range("C2").Select


For x = 1 To NumRows

For y= cells(A).value to cells(B).value
'which code we have to write for comparing a1,b1 are equal or not
ActiveCell.FormulaR1C1 = "=Sum(RC[-1]+1)"

ActiveCell.Offset(x, 0).FillDown
Next
Next


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
Match, then Look Left 4 Columns, then Loop to End of Range ryguy7272 Excel Programming 9 November 22nd 08 08:42 PM
Write variables from a loop, once only Novaloc Excel Programming 1 October 11th 05 04:10 AM
How to write a vba loop for Excel Paul Excel Programming 1 June 4th 05 06:24 AM
Loop,Compare,Write Michael168[_75_] Excel Programming 1 May 25th 04 06:41 PM
Show one range in a combobox and write the 2nd range! Kevin Excel Programming 1 October 17th 03 05:52 AM


All times are GMT +1. The time now is 11:57 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"