当且仅当值相同时,如何创建一个循环来删除 sheet?
How to make a loop to delete a sheet if and only if the values are the same?
我从 SAP 提取数据到 excel,我这样做:
- 事务在 SAP GUI 中自动运行,然后将数据保存在 txt 文件中
- VBA 读取我的 txt 文件
- 在 Excel 温度 sheet 中粘上它,然后在我的 table
中粘上它
- 问题是有时我没有任何数据,因为 SAP 没有找到任何数据,只是它粘贴了我想要的前一个交易的数据(因为我有几个交易要执行)解决我的问题是我想做一个循环“如果我在剪贴板中的数据与温度相同 sheet, select 时间 sheet2 (这将没有数据所有the time)”并将其复制到我的table(这将是空的)
我不确定这是不是正确的方法,但我认为这是可行的并且可以解决问题
代码:
Sub StartExtract()
' Set the sid and client to connect to
W_System = "P10320"
' Run the GUI script
RunGUIScript
' End the GUI session
objSess.EndTransaction
'effacer contenu feuille temp
Sheets("temp").Select
Cells.Select
Selection.Delete Shift:=xlUp
' Switch to the worksheet where the data is loaded to
Sheets("temp").Select
' Load the CSV file
OpenCSVFile
Sheets("BGSOCIAL").Select
Columns("B:G").Select
Selection.ClearContents
Sheets("temp").Range("B:G").Copy
Sheets("BGSOCIAL").Range("B:G").PasteSpecial Paste:=xlPasteValues
Sheets("BGSOCIAL").Select
您无法评估您从中复制的区域是否具有值。但是,我认为如果 Temp 范围为空,我们可以跳过下面的所有内容。我还建议使用值集而不是 xlPasteValues
希望有用。
Sub StartExtract()
' Set the sid and client to connect to
W_System = "P10320"
' Run the GUI script
RunGUIScript
' End the GUI session
objSess.EndTransaction
'effacer contenu feuille temp
Sheets("temp").Select
Cells.Select
Selection.Delete Shift:=xlUp
' Switch to the worksheet where the data is loaded to
Sheets("temp").Select
' Load the CSV file
OpenCSVFile
'Modified code below...
If Application.WorksheetFunction.CountA(Range("B:G")) = 0 Then
'skips as no values in the range.
Else
' Dont need to copy and paste, just set the values to being the same.
Sheets("BGSOCIAL").Range("B:G").Value = Sheets("temp").Range("B:G").Value
End If
Sheets("BGSOCIAL").Select
End Sub
我从 SAP 提取数据到 excel,我这样做:
- 事务在 SAP GUI 中自动运行,然后将数据保存在 txt 文件中
- VBA 读取我的 txt 文件
- 在 Excel 温度 sheet 中粘上它,然后在我的 table 中粘上它
- 问题是有时我没有任何数据,因为 SAP 没有找到任何数据,只是它粘贴了我想要的前一个交易的数据(因为我有几个交易要执行)解决我的问题是我想做一个循环“如果我在剪贴板中的数据与温度相同 sheet, select 时间 sheet2 (这将没有数据所有the time)”并将其复制到我的table(这将是空的)
我不确定这是不是正确的方法,但我认为这是可行的并且可以解决问题
代码:
Sub StartExtract()
' Set the sid and client to connect to
W_System = "P10320"
' Run the GUI script
RunGUIScript
' End the GUI session
objSess.EndTransaction
'effacer contenu feuille temp
Sheets("temp").Select
Cells.Select
Selection.Delete Shift:=xlUp
' Switch to the worksheet where the data is loaded to
Sheets("temp").Select
' Load the CSV file
OpenCSVFile
Sheets("BGSOCIAL").Select
Columns("B:G").Select
Selection.ClearContents
Sheets("temp").Range("B:G").Copy
Sheets("BGSOCIAL").Range("B:G").PasteSpecial Paste:=xlPasteValues
Sheets("BGSOCIAL").Select
您无法评估您从中复制的区域是否具有值。但是,我认为如果 Temp 范围为空,我们可以跳过下面的所有内容。我还建议使用值集而不是 xlPasteValues
希望有用。
Sub StartExtract()
' Set the sid and client to connect to
W_System = "P10320"
' Run the GUI script
RunGUIScript
' End the GUI session
objSess.EndTransaction
'effacer contenu feuille temp
Sheets("temp").Select
Cells.Select
Selection.Delete Shift:=xlUp
' Switch to the worksheet where the data is loaded to
Sheets("temp").Select
' Load the CSV file
OpenCSVFile
'Modified code below...
If Application.WorksheetFunction.CountA(Range("B:G")) = 0 Then
'skips as no values in the range.
Else
' Dont need to copy and paste, just set the values to being the same.
Sheets("BGSOCIAL").Range("B:G").Value = Sheets("temp").Range("B:G").Value
End If
Sheets("BGSOCIAL").Select
End Sub