|
-
Jun 18th, 2013, 05:06 AM
#1
Thread Starter
Addicted Member
[RESOLVED] if else statement
hi
im using thses line of code to pull stuff of an excel sheet
Code:
oRng = oWSSheet2.Cells.Find("Class B", , _
Excel.XlFindLookIn.xlValues, Excel.XlLookAt.xlPart, _
Excel.XlSearchOrder.xlByRows, Excel.XlSearchDirection.xlNext, False)
' MsgBox("Value '" & app oRng.Value & "' found at '" & oRng.Address)
Me.classb = oRng.Offset(0, 42).Value
oRng = Nothing
but sometime some spreadsheets wont have the word class b in it but i get an error if it doesnt. i want to put in an if statement so if its null to go to next piece of code.
how can this be done in vb
if i try this
if orng is not null then
Me.classb = oRng.Offset(0, 42).Value
else
....
but that's not quite right
-
Jun 18th, 2013, 05:43 AM
#2
Thread Starter
Addicted Member
Re: if else statement
when i try this i get an error as my values are in Decimal
Code:
' MsgBox("Value '" & app oRng.Value & "' found at '" & oRng.Address)
If Me.classb = String.Empty Then
Me.classb = 0.0
Else
Me.classb = oRng.Offset(0, 42).Value
End If
anyway around this
-
Jun 18th, 2013, 07:04 AM
#3
Re: if else statement
Try this
Code:
If Not oRng Is Nothing Then
End If
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Jun 18th, 2013, 07:14 AM
#4
Re: if else statement
 Originally Posted by koolsid
Try this
Code:
If Not oRng Is Nothing Then
End If
Or rather:
Code:
If oRng IsNot Nothing Then
End If
Functioanlly equivalent but much more natural, which is why IsNot was added to the language.
-
Jun 18th, 2013, 08:34 AM
#5
Re: if else statement
 Originally Posted by rjhe22
Code:
oRng = oWSSheet2.Cells.Find("Class B",
To note, you appear to be using the double-dot notation, which is notorious for stopping the release of the object, meaning that Excel does not close when your code is completed.
-
Jun 18th, 2013, 09:12 AM
#6
Re: if else statement
@JM: Yup. 
@Grimfort: There is nothing wrong with the usage of two dot rule. You might want to see this?
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Jun 18th, 2013, 09:47 AM
#7
Re: if else statement
 Originally Posted by koolsid
@Grimfort: There is nothing wrong with the usage of two dot rule. You might want to see this?
I don't think there is enough evidence in that blog to backup that statement. I have tried (there are samples I have posted on this forum) using all kinds of methods including forcing GC and ReleaseComObject, and the clear-up was not successful in all circumstances. I won't go into a debate on it here, but from my own experience in this area, it is something to avoid, or at least understand if you get the issue.
-
Jun 19th, 2013, 03:32 AM
#8
Thread Starter
Addicted Member
Re: if else statement
that worked thanks
also will look into the dot stuff thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|