VBA Code check

Alisya

Well-known Member
Joined
Nov 27, 2008
Messages
532
Hi does any one know why this could does not work. I am not getting any errors, it does nothing when i run. I am trying to get the code to look in Col B for N/A, if found then let the user know why msgbox

Code:
Sub Test()
    Dim LR1 As Long
    
    LR1 = Range("C" & Rows.count).End(xlUp).Row
    
    If LR1 < 5 Then LR1 = 5
    If UCase$(Trim$(Sheets(1).Range("B" & LR1).Value)) = "N/A" Then
            MsgBox "There is a new a/c"
    End If

End Sub
 
Sektor what about my query above in #9

This?
Code:
[COLOR=blue]Sub[/COLOR] Test()
 
    [COLOR=blue]Dim[/COLOR] LR1 [COLOR=blue]As[/COLOR] [COLOR=blue]Long[/COLOR]
 
    LR1 = Range("C" & Rows.Count).End(xlUp).Row
 
    [COLOR=blue]If[/COLOR] LR1 < 5 [COLOR=blue]Then[/COLOR] LR1 = 5
 
    [COLOR=blue]If[/COLOR] IsError(Sheets(1).Range("B" & LR1)) [COLOR=blue]Then[/COLOR]
            MsgBox "There is a new a/c"
    [COLOR=blue]End[/COLOR] [COLOR=blue]If[/COLOR]
 
[COLOR=blue]End[/COLOR] [COLOR=blue]Sub[/COLOR]
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
There's no need for Exit Sub because Else part will never be reached if there's error in cell.
 
Upvote 0
Hi Sektor
I don't think the N/A means error....I think the OP is trying to identify a N/A....New Account
 
Upvote 0
Alisya

I'm really hoping this is an additional question to the original (solved) post.
try, untested
Code:
Sub test3()
Dim LR1 As Long, n As Integer, r As Long
LR1 = Sheets("Securities").Range("C" & Rows.Count).End(xlUp).Row
    For r = Range("B" & LR1) To 5 Step -1
        If UCase(Trim(Sheets("Securities").Rows(r))) = "N/A" Then Exit Sub
    Next r
End Sub
 
Upvote 0
Oh dear....see what happens when you can't test something....I just read what I posted and it won't work.
try this
Code:
Sub test3()
Dim LR1 As Long, n As Integer, r As Long
LR1 = Sheets("Sheet1").Range("C" & Rows.Count).End(xlUp).Row
    For r = Range("B" & LR1) To 5 Step -1
        If UCase(Trim(Range("B" & r))) = "N/A" Then Exit Sub
    Next r
End Sub
 
Upvote 0
One last attempt at this before I go nuts and turn to the drink
Code:
Sub test3()
Dim LR1 As Long, n As Integer, r As Long
LR1 = Sheets("Sheet1").Range("C" & Rows.Count).End(xlUp).Row
    For r = LR1 To 5 Step -1
        If UCase(Trim(Range("B" & r))) = "N/A" Then Exit Sub
    Next r
End Sub
 
Upvote 0
Try
Code:
Sub Test()
    Dim LR1 As Long
    Dim c As Range
    LR1 = Range("C" & Rows.Count).End(xlUp).Row
 
    If LR1 < 5 Then LR1 = 5
    For Each c In Sheets(1).Range("B5:B" & LR1)
    If UCase(Trim(c.Value)) = "N/A" Then
            MsgBox "There is a new a/c"
            GoTo EndIt
    End If
    Next c
'Your code here
EndIt:
End Sub
 
Upvote 0
If i was calling this macro in another Macro, then if there is a new a/c would the exit Sub work befoire it goes to 'Some Other code?

Sub MyTest

'My code

ExitRoutine:
Call Test
'Some other code

Exit Sub

End Sub


Try
Code:
Sub Test()
    Dim LR1 As Long
    Dim c As Range
    LR1 = Range("C" & Rows.Count).End(xlUp).Row
 
    If LR1 < 5 Then LR1 = 5
    For Each c In Sheets(1).Range("B5:B" & LR1)
    If UCase(Trim(c.Value)) = "N/A" Then
            MsgBox "There is a new a/c"
            GoTo EndIt
    End If
    Next c
'Your code here
EndIt:
End Sub
 
Upvote 0
Aliysa
This thread seems to be a constantly changing need.
Might be simpler if you explain to us what you actually want the code to do completely, and then we can actually create the script from start to finish
 
Upvote 0
Michael, the code itself is fine, i am trying to make the overall code bulletproof incase of errors so if i was calling the macro into another macro then i want to make sure that when it finds N/A the macro does not keep continuing
 
Upvote 0

Forum statistics

Threads
1,225,156
Messages
6,183,246
Members
453,152
Latest member
ChrisMd

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