Data acquisition from the web
-
- BronzeLounger
- Posts: 1412
- Joined: 08 Jul 2016, 18:53
Re: Data acquisition from the web
Using your link and the information on the page
Range.TextToColumns(F1,xlDelimited) results in compile error
F1-F4005(in this case) would be the destination and I'm guessing the xlDelimited would be the correct choice.
Range.TextToColumns(F1,xlDelimited) results in compile error
F1-F4005(in this case) would be the destination and I'm guessing the xlDelimited would be the correct choice.
-
- Administrator
- Posts: 78620
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Data acquisition from the web
F1 is Excel notation, not VBA. Use Range("F1") in VBA.
You'd have to use something like this:
if the data are on sheet VixData and LastRow is a variable containing the last used row number.
You'd have to use something like this:
Code: Select all
With Worksheets("VixData")
.Range("A1:A" & LastRow).TextToColumns Destination:=.Range("F1"), Comma:=True
End With
Best wishes,
Hans
Hans
-
- BronzeLounger
- Posts: 1412
- Joined: 08 Jul 2016, 18:53
Re: Data acquisition from the web
Code: Select all
Dim LastRow As Long
Dim LastRow As Long
With Worksheets("VixData")
LastRow = .Range("A" & .Rows.Count).End(xlUp).Row - 1
.Range("A1:A" & LastRow).TextToColumns Destination:=.Range("F1"), Comma:=True
End With
There must be some character in row 4006 as LastRow equaled 4006 (but data ends at 4005), the reason I subtracted one. Seems to me that Destination: and Comma: should be replaced by commas in the formula, but
-
- Administrator
- Posts: 78620
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Data acquisition from the web
When you specify arguments to a method, you have to use :=
So for example Comma:=True means that the Comma argument of TextToColumns is set to True, telling Excel to use the comma as delimiter.
So for example Comma:=True means that the Comma argument of TextToColumns is set to True, telling Excel to use the comma as delimiter.
Best wishes,
Hans
Hans
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Re: Data acquisition from the web
You were right to comment out the line .CommandType = 0.
That always fails when the macro is run.
Regarding the data all in column A:
Its either a conflict on your delimiter in Windows Regional Settings.
Check to ensure that the delimiter in the CSV is the same as the delimiter set as the List Separator in the Regional settings dialog (see image below)
Or it could be that your Text Import Wizard has a different delimiter character set in Step 2
Ensure that it is Tab or Comma
Edit: Oh, sorry. It seems you have the CSV import issue resolved.
That always fails when the macro is run.
Regarding the data all in column A:
Its either a conflict on your delimiter in Windows Regional Settings.
Check to ensure that the delimiter in the CSV is the same as the delimiter set as the List Separator in the Regional settings dialog (see image below)
Or it could be that your Text Import Wizard has a different delimiter character set in Step 2
Ensure that it is Tab or Comma
Edit: Oh, sorry. It seems you have the CSV import issue resolved.
You do not have the required permissions to view the files attached to this post.
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.
-
- BronzeLounger
- Posts: 1412
- Joined: 08 Jul 2016, 18:53
Re: Data acquisition from the web
Yes my delimiter is a comma and the data imported is comma delimited. I don't know how where to check whether the delimiter in csv is a commaRudi wrote:You were right to comment out the line .CommandType = 0.
That always fails when the macro is run.
Regarding the data all in column A:
Its either a conflict on your delimiter in Windows Regional Settings.
Check to ensure that the delimiter in the CSV is the same as the delimiter set as the List Separator in the Regional settings dialog (see image below)
I don't know where that setting might be located.
Or it could be that your Text Import Wizard has a different delimiter character set in Step 2
Ensure that it is Tab or Comma
If the import could be accomplished into cells instead of a sting in column, that would be optimal. If that can't be done then Han's suggestions have enabled the data to separated into cells.Edit: Oh, sorry. It seems you have the CSV import issue resolved.
In your code suggestion you used
Code: Select all
strDate = Format(Worksheets("Data").Range("H2").Value, "mm/dd/yy")
On Error Resume Next
Set rgF = .Columns(1).Cells.Find(What:=CDate(strDate), After:=Range("A1"), LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
On Error GoTo 0
-
- BronzeLounger
- Posts: 1412
- Joined: 08 Jul 2016, 18:53
Re: Data acquisition from the web
Oh boy This resulted in Type mismatch
rWith Worksheets("VixData")
LastRow = .Range("A" & .Rows.Count).End(xlUp).Row - 1
.Range("A1:A" & LastRow).TextToColumns Destination:=.Range("B1"), Comma:=True
End With
Set wsSourceV = Sheets("VixData")
Set wsDestinationV = Sheets("Vix")
strDate = Format(Worksheets("VixData").Range("B" & LastRow).Value, "mm/dd/yyyy")
With wsDestinationV
Set rVix = .Columns(1).Cells.Find(What:=CDate(strDate), After:=Range("B1"), LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)[/code]
rVix had been dimensioned as a Range earlier
Anyway the error was run time 13 Type mismatch. This is almost a duplicate of Rudi's code with the exception of setting StrDate to a four digit year.
What did I do incorrectly?
Code: Select all
With Worksheets("VixData")
LastRow = .Range("A" & .Rows.Count).End(xlUp).Row - 1
.Range("A1:A" & LastRow).TextToColumns Destination:=.Range("B1"), Comma:=True
End With
Set wsSourceV = Sheets("VixData")
Set wsDestinationV = Sheets("Vix")
strDate = Format(Worksheets("VixData").Range("B" & LastRow).Value, "mm/dd/yyyy")
With wsDestinationV
Set rVix = .Columns(1).Cells.Find(What:=CDate(strDate), After:=Range("B1"), LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
LastRow = .Range("A" & .Rows.Count).End(xlUp).Row - 1
.Range("A1:A" & LastRow).TextToColumns Destination:=.Range("B1"), Comma:=True
End With
Set wsSourceV = Sheets("VixData")
Set wsDestinationV = Sheets("Vix")
strDate = Format(Worksheets("VixData").Range("B" & LastRow).Value, "mm/dd/yyyy")
With wsDestinationV
Set rVix = .Columns(1).Cells.Find(What:=CDate(strDate), After:=Range("B1"), LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)[/code]
rVix had been dimensioned as a Range earlier
Anyway the error was run time 13 Type mismatch. This is almost a duplicate of Rudi's code with the exception of setting StrDate to a four digit year.
What did I do incorrectly?
-
- Administrator
- Posts: 78620
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Data acquisition from the web
You search in column A on the Vix sheet, but specify that you want to search after cell B1 on the active sheet. That is not possible.
Also, I don't think you should use CDate here.
Also, I don't think you should use CDate here.
Code: Select all
Set rVix = .Columns(1).Cells.Find(What:=strDate, After:=.Range("A1"), LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
Best wishes,
Hans
Hans
-
- BronzeLounger
- Posts: 1412
- Joined: 08 Jul 2016, 18:53
Re: Data acquisition from the web
That is where the soucre cell is and the destination. Why is that not possible? Also the cdate is used in the code part from Rudi. Um could you suggest an alternate?HansV wrote:You search in column A on the Vix sheet, but specify that you want to search after cell B1 on the active sheet. That is not possible.
Also, I don't think you should use CDate here.
Code: Select all
Set rVix = .Columns(1).Cells.Find(What:=strDate, After:=.Range("A1"), LookIn:=xlFormulas, _ LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
-
- Administrator
- Posts: 78620
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Data acquisition from the web
The "After" argument must be one of the cells in the range you want to find in. It tells Excel to start searching from that cell. It cannot search outside the find range.
I'd just omit the CDate - as in the code that I posted.
I'd just omit the CDate - as in the code that I posted.
Best wishes,
Hans
Hans
-
- BronzeLounger
- Posts: 1412
- Joined: 08 Jul 2016, 18:53
Re: Data acquisition from the web
Hans other than not using cdate, I don't see any difference as you are searching in colmn 1. I'm not at the pc currently so I am unable to test.
-
- Administrator
- Posts: 78620
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Data acquisition from the web
I also added a . before Range(…), because without the . the Range refers to the active worksheet, not necessarily to the Vix sheet. Adding the . makes the Range refer to Vix because it is inside the With wsDestinationV … End With block.
Best wishes,
Hans
Hans
-
- BronzeLounger
- Posts: 1412
- Joined: 08 Jul 2016, 18:53
Re: Data acquisition from the web
Disregard, it might have been during the edit, everything still downloads. I dleted the comment.
Hans your suggestion works(?) However the adding of values is giving an error Object defined error
I have added .Range before the .Cells without any change in error.
This is the line where the watch is giving the error as rVix is not null and has the value "11/27/2019".
Hans your suggestion works(?) However the adding of values is giving an error Object defined error
Code: Select all
With wsDestinationV
Set rVix = .Columns(1).Cells.Find(What:=strDate, After:=.Range("A1"), LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
On Error GoTo 0
If rVix Is Nothing Then
MsgBox "Date cannot be found on Vix sheet! Record will be added to the end of the table!", vbExclamation
LastRow = .Cells(1).CurrentRegion.Rows.Count + 1
.Cells("A" & lRow).Value = wsSourceV.Range("B" & LastRow).Value
.Cells("B" & lRow).Value = wsSourceV.Range("C" & LastRow).Value
.Cells("C" & lRow).Value = wsSourceV.Range("D" & LastRow).Value
.Cells("D" & lRow).Value = wsSourceV.Range("E" & LastRow).Value
.Cells("E" & lRow).Value = wsSourceV.Range("F" & LastRow).Value
'If (.Cells(lRow - 1, "B")) - (.Cells(lRow - 1, "C")) < -500 And _
' (.Cells(lRow, "B")) - (.Cells(lRow, "C")) > -500 Then _
' .Range(.Cells(lRow, "B"), .Cells(lRow, "C")).Interior.Color = vbGreen
'.Cells(lRow, "F").Value = "=(R[-1]C*R3C9)+(RC[-1]*R2C9)"
'.Cells(lRow, "G").Value = "=(R[-1]C*R7C9)+(RC[-2]*R6C9)"
'.Cells(lRow, "H").Value = "=RC[-2]/RC[-1]"
'.Cells(lRow, "K").Value = "=AVERAGE(R[-8]C[-6]:R[-1]C[-6])"
'.Cells(lRow, "L").Value = "=AVERAGE(R[-20]C[-7]:R[-1]C[-7])"
'Application.Goto .Cells(lRow, 1), True
ElseIf Not rVix Is Nothing Then
lRow = rVix.Row
.Cells("B" & lRow).Value = wsSourceV.Range("C" & LastRow).Value
.Cells("C" & lRow).Value = wsSourceV.Range("D" & LastRow).Value
.Cells("D" & lRow).Value = wsSourceV.Range("E" & LastRow).Value
.Cells("E" & lRow).Value = wsSourceV.Range("F" & lstrow).Value
'If (.Cells(lRow - 1, "B")) - (.Cells(lRow - 1, "C")) < -500 And _
'(.DCells(lRow, "B")) - (.Cells(lRow, "C")) > -500 Then _
'.Range(.Cells(lRow, "B"), .Cells(lRow, "C")).Interior.Color = vbGreen
'.Cells(lRow, "F").Value = "=(R[-1]C*R3C9)+(RC[-1]*R2C9)"
'.Cells(lRow, "G").Value = "=(R[-1]C*R7C9)+(RC[-2]*R6C9)"
'.Cells(lRow, "H").Value = "=RC[-2]/RC[-1]"
'.Cells(lRow, "K").Value = "=AVERAGE(R[-8]C[-6]:R[-1]C[-6])"
'.Cells(lRow, "L").Value = "=AVERAGE(R[-20]C[-7]:R[-1]C[-7])"
End If
End With
This is the line where the watch is giving the error as rVix is not null and has the value "11/27/2019".
Last edited by bknight on 29 Nov 2019, 16:25, edited 2 times in total.
-
- Administrator
- Posts: 78620
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- BronzeLounger
- Posts: 1412
- Joined: 08 Jul 2016, 18:53
Re: Data acquisition from the web
It works, must have been associated with editing the macro. Please relook at the previous post.
-
- Administrator
- Posts: 78620
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- BronzeLounger
- Posts: 1412
- Joined: 08 Jul 2016, 18:53
Re: Data acquisition from the web
.Cells("B" & lRow).Value = wsSourceV.Range("C" & LastRow).Value ,sorry
-
- Administrator
- Posts: 78620
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Data acquisition from the web
So the first line
.Cells("A" & lRow).Value = wsSourceV.Range("B" & LastRow).Value
works, but not the one below it? If so, does wsSourceV.Range("C" & LastRow) contain an error?
.Cells("A" & lRow).Value = wsSourceV.Range("B" & LastRow).Value
works, but not the one below it? If so, does wsSourceV.Range("C" & LastRow) contain an error?
Best wishes,
Hans
Hans
-
- BronzeLounger
- Posts: 1412
- Joined: 08 Jul 2016, 18:53
Re: Data acquisition from the web
The first part of the line doesn't work in the watch, gives the object defined error
.Cells("B" & lRow).Value
The second part(wsSourceV.Range("C" & LastRow)) works and has the correct value.
I attempted putting in the .Range in front of the .Cells, but that also results in the same error in the watch.
.Cells("B" & lRow).Value
The second part(wsSourceV.Range("C" & LastRow)) works and has the correct value.
I attempted putting in the .Range in front of the .Cells, but that also results in the same error in the watch.
-
- Administrator
- Posts: 78620
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Data acquisition from the web
Try replacing .Cells with .Range:
Cells expects row number and column number as arguments, for example .Cells(lRow, 1)
Range expects a cell address as argument, for example .Range("A" & lRow)
Code: Select all
.Range("A" & lRow).Value = wsSourceV.Range("B" & LastRow).Value
Range expects a cell address as argument, for example .Range("A" & lRow)
Best wishes,
Hans
Hans