473,386 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Delete Cells With Repeating Values

Hello, I have a code like that, which has been using by me, but now I need another one, which won't differ a lot, I hope. Please, analize it, I believe that here I'll find somebody with large luggage of experience. Please, write any suggestions you have.

Expand|Select|Wrap|Line Numbers
  1. Sub test() 
  2.     Dim ws As Worksheet, a, i As Long, ii As Long, b(), n As Long, w(), e 
  3.     With CreateObject("Scripting.Dictionary") 
  4.         For Each ws In Worksheets 
  5.             With ws.UsedRange 
  6.     a = .Value 
  7.     .ClearContents 
  8. End With  
  9.             Redim b(1 To UBound(a, 1) * 2, 1 To UBound(a, 2)) 
  10.             For ii = 2 To UBound(a, 2)  Step 4 
  11.                 For i = 1 To UBound(a, 1) 
  12.                     If Not IsEmpty(a(i, ii)) Then 
  13.                         If Not .exists(a(i, ii)) Then 
  14.                             .Add a(i, ii),  Array(a(i, ii - 1), a(i, ii), a(i, ii - 1), a(i, ii)) 
  15.                         Else 
  16.                             w = .Item(a(i, ii)): w(2) = a(i, ii - 1): w(3) = a(i, ii) 
  17.                             .Item(a(i, ii)) = w 
  18.                         End If 
  19.                     End If 
  20.                 Next 
  21.                 For Each e In .items 
  22.                     n = n + 2 
  23.                     b(n - 1, ii - 1) = e(0): b(n - 1, ii) = e(1): b(n, ii - 1) = e(2): b(n, ii) = e(3) 
  24.                 Next 
  25.                 n = 0: .RemoveAll 
  26.             Next 
  27.             ws. Range("a1").Resize(UBound(b, 1), UBound(b, 2)).Value = b 
  28.             n = 0 
  29.         Next 
  30.     End With 
  31. End Sub 
I was using it to delete unnecessary coordinates from two columns, where first column is named 'x' (for arguments) and another one named 'y' for values. I mean I have a diagram, which is described by many coordinates. I need to delete these coordinates, which aren't useful for this diagram, because one straight line in diagram may be described by only two coordinates describing two points. Or I will say it more clearly - every line is described by linear function. Please check third row under title 'Before'. These columns are repeating after every next two empty columns. So after column A&B we should see E&F etc. Program above is used to delete these coordinates, where arguments have increasing values n+1, where n is any positive number expect zero. Values for each arguments repeat a few times, so it would be looking in Excel like that:

Before:
A B
1. 1 1
2. 2 2
3. 3 2
4. 4 2
5. 5 3
6. 6 3
7. 7 3
8. 8 3
9. 9 4
10. 10 4
11. 11 5
12. 12 6
13. 13 6
14. 14 6
15. 15 7
16. 16 7
.. .. ..

After:
A B
1. 1 1
2. 1 1
3. 2 2
4. 4 2
5. 5 3
6. 8 3
7. 9 4
8. 10 4
9. 11 5
10. 11 5
11. 12 6
12. 14 6
13. 15 7
14. 16 7
.. .. ..

But I would use the code for other purpose. I put now a force on two aspects - if there will be only one-column interval between columns with coordinates and another thing - if the scheme will look now inversely - instead X's will be Y's and vice versa, then I will see diagram in horizontal position. But I find a problem, because I don't know how to change the code. Please, help me anybody.
Dec 4 '07 #1
0 1365

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: vcornjamb | last post by:
Hello, I am developing a web form that contains some buttons and a data grid which has as its last column link buttons that will delete the data associated with that row. Everything works fine,...
4
by: Alex | last post by:
Is there any way to delete the value of a html hidden input field from code-behind? I use an html hidden input to store an array of data. I collect this data using Request.Form or Request.Params....
6
by: Karl Richards | last post by:
I am attempting to delete duplicate rows in a spreadsheet using the Excel object. Does anyone have any idea how to do this? I've looked everywhere that I can find on the Web and have not been...
13
by: Shelley | last post by:
Compare Current Year Worksheet with Previous Year Worksheet and if SSN exists in Current Year Worksheet & Not in Previous Year - Copy this Row from Current Year Worksheet & Paste into Previous Year...
0
by: David C | last post by:
I have a GridView with a Delete link and wondered where the best place was to check and cancel delete of a row/record that is bound to an SqlDatasource. I can use datasource Deleting event or...
1
kirubagari
by: kirubagari | last post by:
is it possible to do deletion in visual basic. 1.04 FF F2 03 37 04 04 FF - FF 03 37 04 04 FF F0 03.....line 1 2.37 04 04 FF EF 03 37 04 - 04 FF 04 FF EE 03 37 04.....line 2 3.04 FF ED 03 37 04...
36
kirubagari
by: kirubagari | last post by:
How about the deletion function.i just modify the insert function to delete function.is it correct.actualy i would like to delete if 04 FF 04 FF (got repeating value) i would like to delete one of...
1
by: redskycorp | last post by:
I have repeating values in my combo box, i do want the values to repeat...any idea how to do that ? The reason is that i am taking the values from my database table "Incomplete" from the "Topic"...
3
by: Claudia d'Amato | last post by:
I would like to delete the current content/value of the cells 3,6 .... 3,18 How can I do this within a *.vbs script? Claudia
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.