If with Loop

hashim217

New Member
Joined
Aug 8, 2011
Messages
11
Hi all,

I need set the value of a cell based on the values of 2 other cells in the same row. Then I need to loop this to do it for all the rows with data. In my code I put ranges D2 and L2 but I need it to go down for each next cell in column A. I hope this makes sense. Any advice would be appreciated.

Regards,

Hash

Code:
Sub MM_Conv()
 
Dim RowCount As String
Dim Cell As Range
 
RowCount = WorksheetFunction.CountA(Columns("A:A"))
 
For Each Cell In Range("A2:A" & RowCount)
    If Range("D2").Value = "LONG" & Range("L2").Value = "C" Then
        Cell.Value = "B"
    End If
Next Cell
 
End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Try

Code:
Sub MM_Conv()
 
Dim RowCount As Long
Dim Cell As Range
 
RowCount = WorksheetFunction.CountA(Columns("A:A"))
 
For Each Cell In Range("A2:A" & RowCount)
    If Cell.Offset(, 3).Value = "LONG" & Cell.Offset(, 11).Value = "C" Then
        Cell.Value = "B"
    End If
Next Cell
 
End Sub
 
Upvote 0
Hi,

When I ran the macro with your code it did not give me an error but the cells are all blank. I am not exactly sure why.

-Hash
 
Upvote 0
Sorry, I didn't spot this error in your code

Rich (BB code):
Sub MM_Conv()
 
Dim RowCount As Long
Dim Cell As Range
 
RowCount = WorksheetFunction.CountA(Columns("A:A"))
 
For Each Cell In Range("A2:A" & RowCount)
    If Cell.Offset(, 3).Value = "LONG" And Cell.Offset(, 11).Value = "C" Then
        Cell.Value = "B"
    End If
Next Cell
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,261
Members
452,901
Latest member
LisaGo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top