Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 为什么IF语句不起作用?类对象属性=范围选择/单元格问题_Vba_Excel - Fatal编程技术网

Vba 为什么IF语句不起作用?类对象属性=范围选择/单元格问题

Vba 为什么IF语句不起作用?类对象属性=范围选择/单元格问题,vba,excel,Vba,Excel,我有一个奇怪的问题。。。我的if语句应该有效,但不知怎的它仍然不。。。我不能理解什么是错的,因为它似乎完全正确。我可以看到选择的目标是A列中的最后一行,然后我将其与EURO_USD对象中的t_date属性进行比较,该属性与列(“A”)中的字符串完全相同。End(xlDown)仍然会跳转到else语句(!)。为什么? 代码 以下为欧元/美元等级 Sub fetch() ' get the function o the ECB URL Dim xDOM_nodeList As MSXML2.IXM

我有一个奇怪的问题。。。我的if语句应该有效,但不知怎的它仍然不。。。我不能理解什么是错的,因为它似乎完全正确。我可以看到选择的目标是A列中的最后一行,然后我将其与EURO_USD对象中的t_date属性进行比较,该属性与列(“A”)中的字符串完全相同。End(xlDown)仍然会跳转到else语句(!)。为什么?

代码

以下为欧元/美元等级

Sub fetch() ' get the function o the ECB URL

Dim xDOM_nodeList As MSXML2.IXMLDOMNodeList
Dim xDom As MSXML2.DOMDocument60
Set xDom = New MSXML2.DOMDocument60

xDom.async = False
xDom.Load "http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"

Do Until xDom.readyState = READYSTATE_COMPLETE
    DoEvents
Loop

xDom.setProperty "SelectionNamespaces", "xmlns:f='http://www.ecb.int/vocabulary/2002-08-01/eurofxref' xmlns:c='http://www.gesmes.org/xml/2002-08-01'"

Set xDOM_nodeList = xDom.SelectNodes("//f:Cube[@currency='USD']")
Curr_ticker = Val(xDOM_nodeList.Item(0).Attributes(1).text)

Set xDOM_nodeList = xDom.SelectNodes("//f:Cube[@time]")
Curr_date = xDOM_nodeList.Item(0).Attributes(0).text
End Sub

Public Property Get ticker()

If Curr_ticker = 0 Then
    Call fetch
    End If
ticker = Curr_ticker

End Property

Public Property Get t_date()

If Curr_date = "" Then
    Call fetch
    End If
t_date = Curr_date

End Property
删除:“

来自罗里


您的t_Date属性正在返回字符串-单元格中有什么?实际日期值?它的格式是否与t_日期相同


使用函数datevalue解决了这个问题

多谢各位。但它仍然不能解决这个问题。它仍然跳转到Else语句,即使选择和欧元兑美元的日期应该是相同的……是的。Excel 2013您的t_Date属性返回字符串-单元格中有什么?实际日期值?它的格式和t_日期一样吗?啊,也许这就是问题所在。单元格值为日期格式。
Sub fetch() ' get the function o the ECB URL

Dim xDOM_nodeList As MSXML2.IXMLDOMNodeList
Dim xDom As MSXML2.DOMDocument60
Set xDom = New MSXML2.DOMDocument60

xDom.async = False
xDom.Load "http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"

Do Until xDom.readyState = READYSTATE_COMPLETE
    DoEvents
Loop

xDom.setProperty "SelectionNamespaces", "xmlns:f='http://www.ecb.int/vocabulary/2002-08-01/eurofxref' xmlns:c='http://www.gesmes.org/xml/2002-08-01'"

Set xDOM_nodeList = xDom.SelectNodes("//f:Cube[@currency='USD']")
Curr_ticker = Val(xDOM_nodeList.Item(0).Attributes(1).text)

Set xDOM_nodeList = xDom.SelectNodes("//f:Cube[@time]")
Curr_date = xDOM_nodeList.Item(0).Attributes(0).text
End Sub

Public Property Get ticker()

If Curr_ticker = 0 Then
    Call fetch
    End If
ticker = Curr_ticker

End Property

Public Property Get t_date()

If Curr_date = "" Then
    Call fetch
    End If
t_date = Curr_date

End Property
If Selection = EURO_USD.t_date Then
  Debug.Print "Date already exist"
Else
  Sheets("EURO_USD").Columns("A").End(xlDown).Offset(1, 0) = EURO_USD.t_date
End If