![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: May 2002
Posts: 6
|
I'm new at this and need some help, Can anyone tell me why this if statement won't work and give me an example of how it can?
Thanks Sheets("Seattle").Select range("h10").Select findvalue = range("h10").Value cut = InputBox("enter the cut") If cut = findvalue Then MsgBox cut End If end sub |
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Feb 2002
Location: Guderup, Denmark
Posts: 287
|
Well, your code seems to work fine.
What is the problem ?? Tommy |
|
|
|
|
|
#3 |
|
New Member
Join Date: May 2002
Posts: 6
|
It will never exe the if statement even when its true.
|
|
|
|
|
|
#4 |
|
Join Date: May 2002
Posts: 73
|
Dim findvalue
Sheets("Sheet1").Select findvalue = Range("h10").Value Cut = InputBox("enter the cut") If Cut = findvalue Then MsgBox Cut End If |
|
|
|
|
|
#5 |
|
Board Regular
Join Date: Feb 2002
Location: Guderup, Denmark
Posts: 287
|
What kind of data is in H10 ?
text or values ? I'm asking, becaurse input returns a string and if you are comparing that against a value the if will not exe. Tommy |
|
|
|
|
|
#6 |
|
Board Regular
Join Date: Feb 2002
Location: Guderup, Denmark
Posts: 287
|
you could try this. The CStr converts the value thats is returned from H10 to text and now it can be compared.
Range("h10").Select findvalue = CStr(Range("h10").Value) Cut = InputBox("enter the cut") If Cut = findvalue Then MsgBox Cut End If regards Tommy |
|
|
|
|
|
#7 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Central Florida, USA
Posts: 7,541
|
I guessed that this is what you wanted?
Sub myCut() Dim cut As Long 'Input the cut wanted. cut = InputBox("Enter the cut wanted:") 'If the cut wanted is in the stock list? 'Note: "StockCut" is a named-range-list! With Worksheets("Sheet1").Range("StockCuts") Set c = .Find(cut, LookIn:=xlValues) If Not c Is Nothing Then firstAddress = c.Address 'If found in stock list display MsgBox. MsgBox "The cut wanted is a stock cut: " & cut 'Check full "StockCuts" list for match. Do Set c = .FindNext(c) Loop While Not c Is Nothing And c.Address <> firstAddress End If 'Not found end search. End With End Sub This code will search a list of stock cuts for a match with a cut inputed, if found on the list, display a message. Hope this is what you wanted? JSW [ This Message was edited by: Joe Was on 2002-05-17 20:08 ] |
|
|
|
|
|
#8 |
|
New Member
Join Date: May 2002
Posts: 6
|
Thanks
All of these examples helped |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|