当且仅当值相同时,如何创建一个循环来删除 sheet?

How to make a loop to delete a sheet if and only if the values are the same?

我从 SAP 提取数据到 excel,我这样做:

我不确定这是不是正确的方法,但我认为这是可行的并且可以解决问题

代码:

   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