code help

Kevin0427

Board Regular
Joined
Mar 31, 2016
Messages
69
The following code never gets to the ELSE and always displays the message box. I suspect that it is because when I print the variables lastrow is right justified and rowfound is left justified so they are not both numbers. But I am not sure and if so I don't know how to fix it.

Code:
'Get Row Number
    rowfound = InputBox("What is the row number of the project?", "Input Row Number")
    
    'If Input box is cancelled exit sub
    If rowfound = "" Then
    Exit Sub
    End If
    
    'Is row number valid?
    lastrow = Sheets("Tracking Log").Range("B:B")(Rows.Count, 1).End(xlUp).Row
    
    Debug.Print lastrow
    Debug.Print rowfound
    
    If rowfound < 15 Or rowfouund > lastrow Then
        MsgBox "Row Number not valid", vbCritical, "Invalid Row Number"
        Exit Sub
    
    Else
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
There is a misspelled identifier:

If rowfound < 15 Or rowfouund > lastrow Then

This probably should be
If rowfound < 15 Or rowfound > lastrow Then
 
Last edited:
Upvote 0
Justification won't affect it, but you've misspelt one of your variables.
If you don't require variable declaration (Option Explicit) within your code, the debugger won't highlight misspelt variables.
 
Upvote 0
Are you saying that you found the typo or that you fixed the typo? it has to be fixed even if it is not the problem.
 
Upvote 0
There is a misspelled identifier:

If rowfound < 15 Or rowfouund > lastrow Then

This probably should be
If rowfound < 15 Or rowfouund > lastrow Then

I guess our posts crossed. Thanks for the help but that did not fix the issue.
 
Upvote 0
I fixed the typo and the code still does not work. When I step through with F8 the message box always happens even when rowfound is between 15 and lastrow.
 
Last edited:
Upvote 0
You are quite right about them no both being numbers.
Try
Code:
    'If Input box is cancelled exit sub
    If rowfound = "" Then
      Exit Sub
    Else
      rowfound = val(rowfound)
    End If
 
Upvote 0
You are quite right about them no both being numbers.
Try
Code:
    'If Input box is cancelled exit sub
    If rowfound = "" Then
      Exit Sub
    Else
      rowfound = val(rowfound)
    End If

PERFECTO !!! Thanks. I was trying .value all over the place with no avail.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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