我是excel宏的新手,我想创建一个循环来标识列范围和希望行范围以删除重复项。目前,我已经走了很长的路要走,它创建了一个excel公式来为以下内容创建宏脚本。
对以下内容的任何帮助将不胜感激,因为我现在有60列,并且需要再添加40列...
谢谢
import pandas as pd
df = pd.DataFrame(
{
'X_1': [-34, -1, -33, 4, 10],
'Y_1': [-58, -4, -70, -74, -66],
'X_2': [-3, -1, -3, 4.0, 1],
'Y_2': [-5, -4, -7, -7.8, -6]})
df['Coordinates_Top_right'] = list(zip(df.X_1, df.Y_1))
df['Coordinates_top_left'] = list(zip(df.X_2, df.Y_2))
df['combine'] = df[['Coordinates_Top_right','Coordinates_top_left']].apply(lambda x: [','.join(map(str, (x[i][j] for i in range(2) for j in range(2))))],axis=1)
答案 0 :(得分:1)
这将执行逐列重复删除:
Sub Kleanup()
For i = 1 To Columns.Count
Columns(i).Cells.RemoveDuplicates Columns:=1, Header:=xlNo
Next i
End Sub
答案 1 :(得分:1)
如果您只关心每列重复项,那么它将起作用。
Sub RemoveDuplicates()
'Stop the screen from updating to reduce lag
Application.ScreenUpdating = False
'Main loop
For i = 1 To 100
ActiveWorkbook.Sheets("Result").Columns(i).RemoveDuplicates Columns:=1, Header:=xlNo
Next
'Reset ScreenUpdating
Application.ScreenUpdating = True
End Sub
答案 2 :(得分:0)
您需要循环!
Sub RemoveDuplicates()
Dim TargetSheet As Worksheet
Set TargetSheet = ActiveWorkbook.Worksheets("Result")
For i = 1 To 100
TargetSheet.Cells(1, i).EntireColumn.RemoveDuplicates Columns:=1, Header:=xlNo
Next i
End Sub