I've made a code that downloads data using webquery from website (several pages) in a loop.
Everything is great but instead of downloading data in the same column ("B2") if to set ActiveSheet.QueryTables(1) it creates one table starting in B2 but on the next loop (next webpage) it will overwrite the previously downloaded data again starting in B2.
It have to add next webpage data into worksheet in another range of cells (100 cells down from B2 in the same column) but even though I've changed the range the data is downloaded in the same position.
If to change i in ActiveSheet.QueryTables(i) it creates multiple tables in different columns (not in the same one).
With ActiveSheet.QueryTables(i)
.Connection = "URL;" & page
.Destination = Range(Cells(n + 1, 2), Cells(n + 100, 2))
.Refresh
End With
i = i + 1
Possibly this solution will solve your problem (assuming that n starts with 1):
.Destination = Range(Cells((n-1)*100 + 2, 2), Cells((n * 100) + 1, 2))
BTW, what you rather need as a .Destination value is this line:
.Destination = Cells((n-1)*100 + 2, 2)
See this MSDN Reference for .Destination property.
Related
Previously, I was using this VBA to collect the data Automatically every time the data change in the Row2. However, currently this script is can't be use again.
When I start, it always shows the pop-up in "Method '_Default' of object 'Range'failed.
And Excel just record/copy the Column A even if there is no change on that row.
Private Sub Worksheet_Calculate()
capturerow = 2
currow = Range("A65536").End(xlUp).Row
Cells(currow + 1, 1) = Cells(capturerow, 1)
Cells(currow + 1, 2) = Cells(capturerow, 2)
Cells(currow + 1, 3) = Cells(capturerow, 3)
Cells(currow + 1, 4) = Cells(capturerow, 4)
End Sub
Right now, I am using Microsoft Excel 2010.
This method function for record data tick based on my MT4 using DDE. I want to analyze the data.
Would you mind helping me about this?
Here I attach the screenshot of the Pop up and Excel
Thank you.
Result in Excel, Pop up in VBA, Pop up in VBA Highlighted
I am writing a VBA script to check all measuring point, who are part of the selection have inspection orders. For this I need to extract a large amount of measering point (ca. 2721) and use them as an input in another transaction.
The problem I have is: What is the most efficient way to extract / export a large amount of data from SAP in a way that I can paste them as an input in SAP?
I can make an export, but I cannot access the exported Excel-file through VBA. I can loop through the datarows and copy every single cell, but this is very slow, as shown below.
row = 1
For i = 1 To session.FindById("wnd[0]/usr/cntlGRID1/shellcont/shell").RowCount - 2
session.FindById("wnd[0]/usr/cntlGRID1/shellcont/shell").CurrentCellRow = i
ThisWorkbook.Sheets("Output2").Cells(row, 1) = session.FindById("wnd[0]/usr/cntlGRID1/shellcont/shell").GetCellValue(i - 1, "TPLNR")
ThisWorkbook.Sheets("Output2").Cells(row, 2) = session.FindById("wnd[0]/usr/cntlGRID1/shellcont/shell").GetCellValue(i - 1, "POINT")
row = row + 1
Next
You should
use an array - instead of writing directly to the sheet
use with to not call session.FindByID... multiple times
Dim arrData As Variant, i As Long
With session.FindById("wnd[0]/usr/cntlGRID1/shellcont/shell")
ReDim arrData(1 To .RowCount - 2, 1 To 2)
For i = 1 To .RowCount - 2
.CurrentCellRow = i
arrData(i, 1) = .GetCellValue(i - 1, "TPLNR")
arrData(i, 2) = .GetCellValue(i - 1, "POINT")
Next
End With
With ThisWorkbook.Sheets("Output2")
.Resize(UBound(arrData, 1), 2).Value = arrData
End With
But maybe it's worth to look into Powerquery to achieve what you want.
I am trying to copy the format of the first row to all the rows that are filled up with data. After that, the rest of the rows (empty) are deleted.
Normally this should be done with the sheet not selected. The code below works good, except when the user has both other sheets and the xsInvestmentSummary jointly selected. In that case, when pasting, the other sheets are also modified.
I don't understand why. In this code, all refers to xsInvestmentSummary.
With xsInvestmentSummary
If .Cells(FilaTitulo + 3, 1).Value <> "" Then
Set CeldaInicio = .Cells(FilaTitulo + 2, 1)
Set CeldaFin = CeldaInicio.End(xlDown)
.Cells(FilaTitulo + 1, 1).EntireRow.Copy
.Range(CeldaInicio, CeldaFin).EntireRow.PasteSpecial Paste:=xlPasteFormats ' After this line, the other selected sheets are modified
Set CeldaInicio = .Cells(CeldaFin.Row + 1, 1)
Set CeldaFin = CeldaInicio.End(xlDown)
.Range(CeldaInicio, CeldaFin).EntireRow.Delete
End If
End With
I have 2 rows of numbers in a source workbook. I would like to copy the first row into another workbook, then make the row below it the sum of the source's first & second rows. My code runs but I can't seem to get excel to read the values of the second row. (aa is the source workbook's sheet)
With aa
For i = 1 To Range(Range("U2").Offset(1, 0), Range("U2").Offset(1, 0).End(xlToRight)).Cells.Count
Set NewValue = Range("U2").Offset(1, i - 1)
TargetWB.Worksheets("Sheet1").Range("D2").Offset(1, i - 1).Value = Range("D2").Offset(0, i - 1) + NewValue.Value
Next
End With
I would like to make the text displayed to become a hyperlink that will take you to the sheet and cell when the text displayed is selected.
What am I doing incorrectly?
Thank you in advance,
If wb.sheets("Coversheet").Cells(lastRowC, 8) <> WS.Cells(i, 5) Then
wb.sheets("Coversheet").Cells(lastRowC + 1, 2) = "Carrier"
wb.sheets("Coversheet").Cells(lastRowC + 1, 3) = "Employee with a $0 salary found. Unable to calculate salary based benefits. Please rerun Census report"
wb.sheets("Coversheet").Cells(lastRowC + 1, 4) = WS.Cells(i, 4).Hyperlinks(1).Address
End If
I would simply do that in your case to create the hyperlink. It's flexible and easy to manipulate.
Dim hyperlinkLocation As String
hyperlinkLocation = "[ActiveWorkBook.Name"&".xls]1!A1" '<- 1 is the sheet index (important in your case)
ActiveWorkSheet.Hyperlinks.Add Anchor:=.(where the link is), Address:=hyperlinkLockation, _
TextToDisplay:=(name of the link)