Excel具有不同修订版的重复文件名 [英] Excel duplicate file name with different revisions

查看:85
本文介绍了Excel具有不同修订版的重复文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Excel,其中我的文件名在一列中,修订号在另一列中。我需要删除重复项(应该保留更高版本的文件并删除lowerversion)。你们可以帮我使用excel VBA吧。



什么我试过了:



我尝试了什么(我是VBA的新手,在google的帮助下尝试了以下内容)



I have an Excel where i have file names in one column with the revision numbers in another column. I need to remove the duplicates(file with higher version should be retained and lowerversion deleted).Can you guys help me with excel VBA for this.

What I have tried:

What i have tried( i am new to VBA , tried the following with help of google)

with Sheets("Sheet1")
LRow1 = .Cells(Rows.Count, 1).End(xlUp).row
LRow3 = "A1:" & getColumnAlpha & LRow1

For d = 2 To LRow1
	Cells(d, 4) = Cells(d, 1) & "_" & Cells(d, 3)
Next d
Range("A2:F" & LRow1).Sort Key1:=Range("D2:D" & LRow1), order1:=xlAscending, Header:=xlNo
'Sheets("Sheet1").Columns(4).Copy Destination:=Sheets("Test").Columns(2)
Dim test As String
test = LRow1
finishedRow = LRow1
'finishedRow() = test.ToStringArray
'ReDim finishedRow(LRow1) As String
row = 1
resultRow = 1
index = 1

Do While .Range("D" & row) <> ""

	If UBound(Filter(finishedRow, row)) < 0 Then
		finishedRow = row
		index = index + 1
		innerRow = 1

		Do While .Range("D" & innerRow) <> ""


			If UBound(Filter(finishedRow, innerRow)) < 0 Then

				If .Range("D" & row) = .Range("D" & innerRow) Then

					If .Range("B" & row) < .Range("B" & innerRow) Then
						'Update time in result record
						'Sheets("Sheet1").Range("B" & resultRow) = "Delete"
						Rows(resultRow).EntireRow.Delete


					End If

					'Add row to record array
					finishedRow = innerRow
					index = index + 1

				End If

			End If

			'Increase inner row
			innerRow = innerRow + 1

		Loop

		'Increase result row
		resultRow = resultRow + 1

	End If

	'Increase row
	row = row + 1
Loop

End With



此代码删除重复但需要多次运行宏


This code removes duplicates but requires the macro to be run multiple times

推荐答案

对不起,这不是代码编写服务。请参阅 Excel 2010中的VBA入门 [ ^ ] 。
Sorry this is not a code writing service. See Getting Started with VBA in Excel 2010[^].


简单,对数据进行排序以对它们进行分组,然后单步执行每一行并删除不需要的行...
Simple, sort your data to group them, then step through each row and delete the unwanted rows...


您需要告诉我们列中的内容,因为我们只能猜测你的代码在做什么。



你的问题可能与你删除一行时的数据有关在该行下方向上移动,如果你不小心,它会让你跳过一些数据。
You need to tell us what is in the columns, because we can only guess what your code is doing.

Your problem is probably linked to the fact that when you delete a row, the data below that row moves up, and if you are not careful, it makes you skip some data.


这篇关于Excel具有不同修订版的重复文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆