Nested If problem

tourless

Board Regular
Joined
Feb 8, 2007
Messages
144
Office Version
  1. 365
Platform
  1. Windows
Hi Folks.

I'm having a problem with the following task... With range H4 to H last row, if cell begins with "Net", then look at cell in same row in Column D and if D cell value is positive number, place "1009992" into cell in same row in Column C. If H cell does not start with "Net", move on to the next row. I have captured my last row and can search the range for cells beginning with "Net" but then I'm lost with offsets and testing the value in D. Here's what I've got so far and it's not working at all.

VBA Code:
With Sheets("My Sheet")
        For Each cell In .Range("H4:H" & lRow)
            If UCase(Left(cell.Value, 3)) = "Net" Then
                If ws.Cells(i, 4).Value > 0 Then
                ws.Cells(i, 3).Value = "1009992"
            End If
        Next
    End With
 
Hmmm... That is odd. "UCase" should not cause that kind of error.
If it works without it, that is fine, but just note that it must then equal "Net" exactly, and not something like "NET" or "net".

What type of values do you have in column H?
It's a payroll file I'm manipulating for proper import into QuickBooks. H values range from starting with 401 or a smattering of words but only a subset begin with the word Net, exactly as 'Net'. I've got more work to do on the file before it's ready but this was a big sticking point.
 
Upvote 0

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
OK. I am thinking that there may be some non-text values or something that it doesn't like applying the UCASE to (though when I tried blanks and numbers, I did not get any errors).
I suppose if it seems to work with that change, then just roll with it!
 
Upvote 0

Forum statistics

Threads
1,214,787
Messages
6,121,561
Members
449,038
Latest member
Guest1337

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