Change values after VLookup

rollingzep

Board Regular
Joined
Nov 18, 2013
Messages
214
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I have a excel sheet on which I have a column with data filled after a Vlookup.
Among the values that come in, I have a Column BE with value "NR", which is a valid value.

I need to change it to "N" in the same column, BE

Set ws = wbexcel.Sheets("TSS Trans")

lrow = ws.Range("AG" & Rows.Count).End(xlUp).Row

For i = 2 To LastRow
If ws.Range("BE" & i).Value = "NR" Then
ws.Range("BE" & i).Value = "N"
End If
Next i

is not working
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Hi All,

I have a excel sheet on which I have a column with data filled after a Vlookup.
Among the values that come in, I have a Column BE with value "NR", which is a valid value.

I need to change it to "N" in the same column, BE

Set ws = wbexcel.Sheets("TSS Trans")

lrow = ws.Range("AG" & Rows.Count).End(xlUp).Row

For i = 2 To LastRow
If ws.Range("BE" & i).Value = "NR" Then
ws.Range("BE" & i).Value = "N"
End If
Next i

is not working
First thing I can think of is that you have
VBA Code:
lrow=  ws.Range("AG" & Rows.Count).End(xlUp).Row

But here you have

VBA Code:
    For i = 2 To LastRow

Should it be

VBA Code:
 For i = 2 To Lrow

perhaps?
 
Upvote 0
First thing I can think of is that you have
VBA Code:
lrow=  ws.Range("AG" & Rows.Count).End(xlUp).Row

But here you have

VBA Code:
    For i = 2 To LastRow

Should it be

VBA Code:
 For i = 2 To Lrow

perhaps?
My bad..

I changed it to lrow and get "Type mismatch" error on the Bold line

lrow = ws.Cells(Rows.Count, "AG").End(xlUp).Row

For i = 2 To LastRow
If ws.Range("BE" & i).Value = "NR" Then
ws.Range("BE" & i).Value = "N"
End If
Next i
 
Upvote 0
My bad..

I changed it to lrow and get "Type mismatch" error on the Bold line

lrow = ws.Cells(Rows.Count, "AG").End(xlUp).Row

For i = 2 To LastRow
If ws.Range("BE" & i).Value = "NR" Then
ws.Range("BE" & i).Value = "N"
End If
Next i
When you say you changed it to lrow do you mean this:

VBA Code:
lrow = ws.Cells(Rows.Count, "AG").End(xlUp).Row

For i = 2 To lRow
If ws.Range("BE" & i).Value = "NR" Then
ws.Range("BE" & i).Value = "N"
End If
Next i

If so, did that give you a Type mismatch error?
 
Upvote 0
When you say you changed it to lrow do you mean this:

VBA Code:
lrow = ws.Cells(Rows.Count, "AG").End(xlUp).Row

For i = 2 To lRow
If ws.Range("BE" & i).Value = "NR" Then
ws.Range("BE" & i).Value = "N"
End If
Next i

If so, did that give you a Type mismatch error?
I did change it to lrow but got the Type mismatch error

<code>
lrow = ws.Cells(Rows.Count, "AG").End(xlUp).Row

For i = 2 To lrow
If ws.Range("BE" & i).Value = "NR" Then
ws.Range("BE" & i).Value = "N"
End If
Next i

</code>
 
Upvote 0
I did change it to lrow but got the Type mismatch error

<code>
lrow = ws.Cells(Rows.Count, "AG").End(xlUp).Row

For i = 2 To lrow
If ws.Range("BE" & i).Value = "NR" Then
ws.Range("BE" & i).Value = "N"
End If
Next i

</code>
Give this a try

VBA Code:
Sub Rollingzep()

Dim lrow As Long
Dim i As Long

lrow = Cells(Rows.Count, "AG").End(xlUp).Row

For i = 2 To lrow
If Range("BE" & i).Value = "NR" Then Range("BE" & i).Value = "N"
Next i

End Sub
 
Upvote 0
Give this a try

VBA Code:
Sub Rollingzep()

Dim lrow As Long
Dim i As Long

lrow = Cells(Rows.Count, "AG").End(xlUp).Row

For i = 2 To lrow
If Range("BE" & i).Value = "NR" Then Range("BE" & i).Value = "N"
Next i

End Sub
I tried and I did not get that error but the values did not change
 
Upvote 0
I tried and I did not get that error but the values did not change

The code works for me, and it changed the "NR" on my worksheet to "N". are you able to post a sample of your data?
1663774001163.png

The above is for TSS Trans

<code>

'Read HQLA_FR2052A_ELIG_AST_CL_DESGTN from HQLA's sheet

Set ws = wbexcel.Sheets("TSS Trans")

ws.Range("BE2:BE" & ws.Cells(Rows.Count, "AG").End(xlUp).Row).FormulaR1C1 = "=VLOOKUP(""*""&RC[-24]&""*"",HQLA!C1:C3,3,0)"

'Change NR to N in BE

'lrow = ws.Cells(Rows.Count, "AG").End(xlUp).Row
lrow = Range("AG" & Rows.Count).End(xlUp).Row

For i = 2 To lrow
If Range("BE" & i).Value = "NR" Then
Range("BE" & i).Value = "N"
End If
Next i

</code>
 
Upvote 0
View attachment 74452

The above is for TSS Trans

<code>

'Read HQLA_FR2052A_ELIG_AST_CL_DESGTN from HQLA's sheet

Set ws = wbexcel.Sheets("TSS Trans")

ws.Range("BE2:BE" & ws.Cells(Rows.Count, "AG").End(xlUp).Row).FormulaR1C1 = "=VLOOKUP(""*""&RC[-24]&""*"",HQLA!C1:C3,3,0)"

'Change NR to N in BE

'lrow = ws.Cells(Rows.Count, "AG").End(xlUp).Row
lrow = Range("AG" & Rows.Count).End(xlUp).Row

For i = 2 To lrow
If Range("BE" & i).Value = "NR" Then
Range("BE" & i).Value = "N"
End If
Next i

</code>
Hmmm, maybe the codes are not working because the value on “BE” is the result of a formula.

If you manually change the values on “BE” and typed “NR” does that do anything?
 
Upvote 0

Forum statistics

Threads
1,214,589
Messages
6,120,416
Members
448,960
Latest member
AKSMITH

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