Computing.Net > Forums > Office Software > Ms excel

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Ms excel

Reply to Message Icon

Name: chai mf
Date: June 8, 2003 at 20:01:11 Pacific
OS: win95
CPU/Ram: 300/128
Comment:

How to write a macro to delete 2 or more same value cell and keep the latest cell only, eg, cell a1=xx, a2=xx, a3=xx, a4=xx, I would like to delete a1, a2, a3 and keep a4 only without using cell reference.



Sponsored Link
Ads by Google

Response Number 1
Name: A Certain TH
Date: June 9, 2003 at 02:11:38 Pacific
Reply:

What you are asking is very possible, and probably very easy. However - the question in its current form can't be easily answered.

Do you want the cells cleared or removed? Are they part of a list, so you want the list to be re-arranged? Is the latest cell always at the bottom of the pile? How often would you like the macro to run, and what would you like to trigger it? Are the elements calculated fields or hard-coded? If they are calculated, then are other parts of the list dependent on them (ie. are we going to screw something else up if we delete them)? Will the list always be in the same place? Do you want just the one cell deleted or is it part of a row of information that needs to go?

There are almost certainly more questions than this that need to be asked.

Writing a quick macro involves knowing exactly what you want, or you end up taking much more time further down the line.

Cheers
Tom


0

Response Number 2
Name: chai
Date: June 9, 2003 at 15:09:09 Pacific
Reply:

Just delete any repeated cell value, that is all.


0

Response Number 3
Name: A Certain TH
Date: June 9, 2003 at 15:35:43 Pacific
Reply:

Well, this would work, then. (I've written it in a way that doesn't require using greater than or less than symbols which this forum doesn't display correctly. That way you can just copy and paste the code directly into the XL VBA module you want)


Option Explicit
Sub CleanList()
Dim t As Integer, c As Integer, x As Integer

t = Cells(65535, 1).End(xlUp).Row
Do
For x = 1 To t - 1
If x = t Then Exit For
If Cells(x, 1) = Cells(t, 1) Then If x Mod 2 = 0 Then Cells(x, 1).Delete (xlShiftToLeft) Else Cells(x, 1).Delete (xlShiftUp): x = x - 1: t = t - 1
Next x
t = t - 1
If t = 1 Then Exit Do
Loop
End Sub


Sorry its a bit rough and ready.

Cheers
Tom


0

Response Number 4
Name: chai mf
Date: June 12, 2003 at 22:46:35 Pacific
Reply:

Thanks Tom


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Office Software Forum Home


Sponsored links

Ads by Google


Results for: Ms excel

MS Excel 2002 wont open a PDF link www.computing.net/answers/office/ms-excel-2002-wont-open-a-pdf-link/5209.html

MS Excel - Change text with IF www.computing.net/answers/office/ms-excel-change-text-with-if-/5644.html

Restrict value in MS Excel www.computing.net/answers/office/restrict-value-in-ms-excel/3550.html