Hello guru's.
I have always struggled with loop...do
and I need to do more study on this theory.
CONCEPT:
code that allows me to loop through a worksheet
and move Manager Name (find d.value) to 2 rows above Store Number (find c.value).
The data sheet has various rows in-between c.value and d.value
Whilst the data is all in column "A",
I thought it would be easier to move the entire row instead of cell "A" (but not fussed).
This code seems to always loop back to A12 and not move on to A19, A56 etc and could be .findnext
CELL DATA:
*********************************************************************
A12 = <blank><blank>
A13 = Company Division Name (various text)
A14 = Store Number & Name (always starts with text "No." then text filler)
A15 + A... = general text comment (can be multiple rows)
A16 = Manager Name (always starts with text "Emp No:" then text filler)
Move A16 to A12, then clear A16 contents
*********************************************************************
A19 = <blank><blank>
A20 = Company Division Name (various text)
A21 = Store Number & Name (always starts with text "No." then text filler)
A22 + A... = general text comment (can be multiple rows)
A26 = Manager Name (always starts with text "Emp No:" then text filler)
Move A26 to A19, then clear A26 contents
*********************************************************************
A56 = <blank><blank>
A57 = Company Division Name (various text)
A58 = Store Number & Name (always starts with text "No." then text filler)
A59 + A... = general text comment (can be multiple rows)
A65 = Manager Name (always starts with text "Emp No:" then text filler)
Move A65 to A56, then clear A65 contents
*********************************************************************
and so on.....
</blank></blank></blank></blank></blank></blank>
I have always struggled with loop...do
and I need to do more study on this theory.
CONCEPT:
code that allows me to loop through a worksheet
and move Manager Name (find d.value) to 2 rows above Store Number (find c.value).
The data sheet has various rows in-between c.value and d.value
Whilst the data is all in column "A",
I thought it would be easier to move the entire row instead of cell "A" (but not fussed).
This code seems to always loop back to A12 and not move on to A19, A56 etc and could be .findnext
CELL DATA:
*********************************************************************
A12 = <blank><blank>
A13 = Company Division Name (various text)
A14 = Store Number & Name (always starts with text "No." then text filler)
A15 + A... = general text comment (can be multiple rows)
A16 = Manager Name (always starts with text "Emp No:" then text filler)
Move A16 to A12, then clear A16 contents
*********************************************************************
A19 = <blank><blank>
A20 = Company Division Name (various text)
A21 = Store Number & Name (always starts with text "No." then text filler)
A22 + A... = general text comment (can be multiple rows)
A26 = Manager Name (always starts with text "Emp No:" then text filler)
Move A26 to A19, then clear A26 contents
*********************************************************************
A56 = <blank><blank>
A57 = Company Division Name (various text)
A58 = Store Number & Name (always starts with text "No." then text filler)
A59 + A... = general text comment (can be multiple rows)
A65 = Manager Name (always starts with text "Emp No:" then text filler)
Move A65 to A56, then clear A65 contents
*********************************************************************
and so on.....
Code:
Dim c As Range, d As Range
Lrow = Cells(Rows.Count, 1).End(xlUp).Row ' Gets the last populated row in Col A
With Worksheets("Import").Range("A2:A" & Lrow)
Set c = .Find("No.*", LookIn:=xlValues, LookAt:=xlPart, SearchDirection:=xlNext)
If Not c Is Nothing Then
'firstAddress = c.Address (I removed this to find the row number)
firstAddress = c.Row
Set d = .Find("Emp No:*", LookIn:=xlValues, LookAt:=xlPart, SearchDirection:=xlNext)
If Not d Is Nothing Then
'SecondAddress = c.Address (I removed this to find the row number)
SecondAddress = d.Row
Do
Range("A" & firstAddress - 2).Value = d
Range("A" & SecondAddress).ClearContents
Set c = .FindNext(c)
Set d = .FindNext(d)
If c Is Nothing Then
GoTo DoneFinding
End If
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End If
DoneFinding:
End sub
</blank></blank></blank></blank></blank></blank>