Option Explicit
Sub WakesMB()
Dim WF As Object, Rng As Range, sRng As Range
Dim Rws As Long, Min_ As Long, jJ As Long, Tmp As Long
Rws = Cells(Rows.Count, "a").End(xlUp).Row
Set Rng = Range("A3:A" & Rws)
Set WF = Application.WorksheetFunction
Min_ = WF.Min(Range(Cells(3, "A"), Cells(Rws, "A")))
For jJ = Cells(1, 4).Value - 1 To Min_ Step -1
Set sRng = Rng.Find(jJ, , xlFormulas, xlWhole)
If sRng Is Nothing Then
Tmp = jJ
Else
sRng.Offset(1).EntireRow.Insert
sRng.Offset(1).Resize(, 4).Value = Cells(2, "A").Resize(, 4).Value
Cells(2, "A").Resize(, 4).Value = ""
Exit For
End If
Next jJ
End Sub
You should be able to run this on subsequent sheets, assuming that they all follow the same construct. Or do you mean that you want to take an item from sheet 1, and put it to all sheets?
What i want to do is enter a new customer name in A5 and account number in A6...
Then run code that looks down column b find the nearest lower match to A6,
then copies row5 and inserts it after the line that contains the lower match.
I have tried loads of different idea's you can find them in the attached.
Re: Never pastes in right line. Nearest number to number in a given cell.
Hi
Your example file and your recut of my code don't seem to align. Can you recheck your example file and check and confirm exactly where the customer name and ID are going to be located.
Also, the data in column B is either not sorted, or text sorted. Exactly what is going to be the situation regarding this data, and any new data to be included (with regard to value cf text).
Re: Never pastes in right line. Nearest number to number in a given cell.
Hi Rylo
The attachment is a snap shot of the file i am working on.
Row 5 is the new customer line, A5 and B5 are customer name and account number.
B6 down is the current customers account number and A6 down would be there names,
there are over 500 on the original file, but they have to stay in the order they are in.
The daily data is supplied in hard copy only, never electronic so i cant change the
sort..... I suppose that column B is sorted as text hence the strange order, but this
can not be changed.... life is never straight forward.
When new customers decide to use this system we have to add them to this list normally
it is a new highest number, but occasionally one of the older numbers come on line.
and just to be difficult some of the really old ones have alpa codes (not numeric).
I tried to get the code you supplied to work hence it not linking up as you put it, I am very
new to all this so I have got confused, trying to make it work..... Sorry.
Bookmarks