ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to write a for loop to get the range between a ,b columns (https://www.excelbanter.com/excel-programming/430422-how-write-loop-get-range-between-b-columns.html)

tom

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

JLGWhiz[_2_]

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




Jacob Skaria

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


Patrick Molloy

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



Patrick Molloy

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




All times are GMT +1. The time now is 12:11 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com