Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-17-2018, 06:40 AM
gummybear gummybear is offline trouble with code Windows 7 64bit trouble with code Office 2010 64bit
Novice
trouble with code
 
Join Date: Apr 2018
Posts: 9
gummybear is on a distinguished road
Default trouble with code

I am very new to excel and vba code and forums. I will try to explain my issue to the best of my knowledge. I will make mistake and my not give the proper grammar so if you would be kind. Thank you. Here is my issue. I am making a comparison with dates that I have on my spreadsheet and from the website. I wrote this code:
If dos >= sDate And dos <= Term _
Or dos >= sDate And Term = #1/1/1900# Then
[f1].Offset(i - 1, 0) = "covered"


else
[f1].Offset(i - 1, 0) = " not covered"

It works fine until the website returns a blank cell. I then get an error message "type mismatch" I undertand it is because the cell is blank. I though putting #1/1/1900# would fix this but it doesn't. I also noticed in my local window the value for Term looks like this " ". Can this be fixed?
Attached Images
File Type: png type mismatch error.PNG (626 Bytes, 18 views)
Reply With Quote
  #2  
Old 04-17-2018, 11:19 AM
NoSparks NoSparks is offline trouble with code Windows 7 64bit trouble with code Office 2010 64bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 831
NoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really nice
Default

You need to deal with Term prior to getting to this point in your code.
This should give an idea...
Code:
Sub Testing()

Dim Term As Variant

'don't know how your variable is being assigned so...
    Term = " "
'check if its a date
    If Not IsDate(Term) Then
        'assign a date
        Term = DateSerial(1900, 1, 1)
    End If
    
'message box to show what Term currently is
    MsgBox Term

End Sub
Reply With Quote
  #3  
Old 04-19-2018, 08:55 AM
gummybear gummybear is offline trouble with code Windows 7 64bit trouble with code Office 2010 64bit
Novice
trouble with code
 
Join Date: Apr 2018
Posts: 9
gummybear is on a distinguished road
Default trouble with code

My "Term" is dim as string so I can pull it from the website and are you saying I should use your if statement to check if it is a date and if not then make return a date like 1/1/1900?
Reply With Quote
  #4  
Old 04-19-2018, 12:26 PM
gummybear gummybear is offline trouble with code Windows 7 64bit trouble with code Office 2010 64bit
Novice
trouble with code
 
Join Date: Apr 2018
Posts: 9
gummybear is on a distinguished road
Default trouble with code

Quote:
Originally Posted by NoSparks View Post
You need to deal with Term prior to getting to this point in your code.
This should give an idea...
Code:
Sub Testing()

Dim Term As Variant

'don't know how your variable is being assigned so...
    Term = " "
'check if its a date
    If Not IsDate(Term) Then
        'assign a date
        Term = DateSerial(1900, 1, 1)
    End If
    
'message box to show what Term currently is
    MsgBox Term

End Sub

I ran your code and it answered my question. Thank you so much.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble with me animations Halesowenmum PowerPoint 5 11-21-2017 04:14 AM
trouble with code Trouble with Hyperlinks DanielMcCrea Word 1 09-27-2017 02:35 PM
trouble with code VBA Code to search for field codes with certain text before the Field code and to change style welcometocandyland Word VBA 4 02-08-2017 06:53 PM
trouble with code Parsing Code Macro Trouble! Snaybot Excel Programming 1 05-15-2016 08:33 PM
I'm having trouble doing these tasks jackmackfack Word 4 02-19-2015 06:46 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:10 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft