VBA find sporadic error

MrSak87

New Member
Joined
Jan 8, 2015
Messages
44
Hi guys

I have a section of code which looks through a section of data, finds it and copies it somewhere else. Essentially I have milliseconds running down the A column from 0 to 40000 - I want to pluck out numbers from what I type in a box in the Ca column.

Dim x As Range, y As Range
Set x = Columns(1).Find(Cells(3, "ca").Value, LookIn:=xlValues, LookAt:=xlPart)
Set y = Columns(1).Find(Cells(4, "ca").Value, LookIn:=xlValues, LookAt:=xlPart)
Range(Cells(x.Row, 1), Cells(y.Row, 1)).Resize(, 7).Copy

The codes only works under certain conditions. i.e if I type in 0.1 seconds to 0.9 or 5.1 to 5.9

However it doesn't like it if it crosses up into the next second i.e 0.6 to - 2 seconds. And it especially doesn't like it if the values I'm plucking out are above 10 seconds. Some times I can fix this by reversing the values i.e 10.9 to 10.1 but I still get errors.

Is my code wrong? is there a more robust version?

Thank you for your time
 

CharlesChuckieCharles

Well-known Member
Joined
May 10, 2011
Messages
2,153
Unless Column A is strickly sorted and your input cells are ascending in Column CA

There is a chance that Row X may be > Row Y ie Range(Cells(x.Row, 1), Cells(y.Row, 1)) might end up like Range(Cells(23,1),Cells(9,1))
 

MrSak87

New Member
Joined
Jan 8, 2015
Messages
44
How do you mean?

instead of...

Dim x As Range, y As Range
Set x = Columns(1).Find(Cells(3, "ca").Value, LookIn:=xlValues, LookAt:=xlPart)
Set y = Columns(1).Find(Cells(4, "ca").Value, LookIn:=xlValues, LookAt:=xlPart)
Range(Cells(x.Row, 1), Cells(y.Row, 1)).Resize(, 7).Copy

have

Dim x As Range, y As Range
Set x = Columns(1).Find(Cells(4, "ca").Value, LookIn:=xlValues, LookAt:=xlPart)
Set y = Columns(1).Find(Cells(3, "ca").Value, LookIn:=xlValues, LookAt:=xlPart)
Range(Cells(x.Row, 1), Cells(y.Row, 1)).Resize(, 7).Copy

?
 

Forum statistics

Threads
1,081,793
Messages
5,361,325
Members
400,627
Latest member
Mcomeaux

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top