Data Record Automatically Every Time the Value Changing - excel

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

Related

How to use exported data as input in SAP with VBA

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.

Dynamic excel sum function

I am trying to make a sum formula on a dynamic range. Much like in a pivot table.
Taking a look on the picture I want L15 to be the sum of the range from L16 to the blank row. As the range is dynamic I am not sure how to write it on my code. So far what I have is this:
If out.Range("A15").Cells(i, 1) = "Aktier" Then
out.Range("L15").Cells(i, 1) = Application.WorksheetFunction.Sum(Range("L15").Cells(i + 1, 1), Range("L15").Cells(i + 1, 1).End(xlDown))
End If
So my question is basically how do I write something like Sum(A1:End(xlDown))? :)
Hope you can help me out guys! :D
Thanks in advance!
First I would recommend that every time that's possible, you get a structure more Data Base-like, so I would have a column repeating the concept and then you could use the Excel SUMIF function easily.
Probably that's not your case (that seems the output of an accounting program). Taking advantage of using VBA macros, you can use a loop to generate the column I mentioned before (you could do the sum as well using the concept, but I believe is cleaner generating a better data format). Please see the image below:
Sub Add_Concepts()
i = 1
Concept = Cells(i, 2)
i = 2
Do While (Cells(i, 2) <> "")
Cells(i, 1) = Concept
If Cells(i + 1, 2) = "" Then 'Change in concept
Concept = Cells(i + 2, 2) 'New concept
i = i + 2 'add 2 to skip the New concept line and the white space
End If
i = i + 1
Loop
End Sub
Now you can use the regular Excel functions.
Hope this helps!
Skipping Steps
Snippet:
If out.Range("A15").Cells(i, 1) = "Aktier" Then
With out.Range("L15")
.Cells(i, 1) = Application.WorksheetFunction _
.Sum(.Parent.Range(.Offset(1), .Offset(1).End(xlDown)))
End With
End If
Working example:
Option Explicit
Sub SumToBlank()
Dim out As Worksheet: Set out = ThisWorkbook.Worksheets("Sheet1")
Dim i As Long: i = 1
If out.Range("A15").Cells(i, 1) = "Aktier" Then
With out.Range("L15")
.Cells(i, 1) = Application.WorksheetFunction _
.Sum(.Parent.Range(.Offset(1), .Offset.End(xlDown)))
End With
End If
End Sub

Paste function modifying other sheets

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

How can I include a hyperlink to a cell in another sheet?

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)

Webqueries multiple tables into one column

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.

Resources