CALEB23
New Member
- Joined
- Oct 1, 2024
- Messages
- 4
- Office Version
- Prefer Not To Say
- Platform
- Windows
- Web
Hello All.
I created a macro wherein the data captured from SAP and imported via power query will automatically pasted on another sheet of the same worksheet, what happened is that even though the query is updated once I ran the macro it captured the previous data generated from power query. What will be the correct script to capture the correct data?
I appreciate any help you can provide.
PnL sheet - exported data from SAP and link to the worksheet using power query
PnL Bal - sheets wherein the data from PnL sheet be pasted
Here is my sample script.
I created a macro wherein the data captured from SAP and imported via power query will automatically pasted on another sheet of the same worksheet, what happened is that even though the query is updated once I ran the macro it captured the previous data generated from power query. What will be the correct script to capture the correct data?
I appreciate any help you can provide.
PnL sheet - exported data from SAP and link to the worksheet using power query
PnL Bal - sheets wherein the data from PnL sheet be pasted
Here is my sample script.
VBA Code:
#If VBA7 Then ' Excel 2010 or later
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal Milliseconds As LongPtr)
#Else ' Excel 2007 or earlier
Public Declare Sub Sleep Lib "kernel32" (ByVal Milliseconds As Long)
#End If
Sub PnL_Update()
Sheets("PnL").Visible = True
Sheets("PnL").Select
ActiveWorkbook.RefreshAll
DoEvents
Sleep 10000
Sheets("PnL").Select
Range("A2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets("PnL Bal").Select
Dim lastrow As Long
lastrow = Range("A" & Rows.Count).End(xlUp).Row + 1
Range("A" & lastrow).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sleep 10000
Sheets("PnL Bal").Activate
Worksheets("PnL").Visible = False
End Sub
Last edited by a moderator: