Using Do Loops to copy data
On Apr 27, 12:06 pm, Mahnian
wrote:
I need a bit of code that will search through each cell in a column and look
for "Agent Name:" then choose cell to its right and create a new sheet with
the value of the selected cell as the name.
Below I have added what I tried, which obviously did not work. Any help on
this would be greatly appreciated. (Note, I can make the new sheet and name
it, so my test code just had a msgbox pop up with the value for testing)
=-=-=-=-=-=-=-=
Dim rngEdit As Range
Dim trow As Integer
Dim tcol As Integer
Dim tname As String
Sub LoopIt()
trow = 1
tcol = 3
Set rngEdit = ActiveSheet.Cells(trow, tcol)
Do Until rngEdit.Value = "Agent Name:"
trow = trow + 1
Loop
tcol = tcol + 1
tname = ActiveSheet.Cells(trow, tcol).Value
tcol = tcol - 1
MsgBox trow & " " & tcol
End Sub
It seems as if you created an infinite loop. Hopefully you know that
ctrl+Pause/Break will interrupt code execution. The problem is that
you have set up a condition with rngEdit.Value, but you have not
created a way to change rngEdit.Value (ie rngEdit.Value will always be
Cells(1, 3)). Copy and paste your Set statement inside the Do Loop
after the trow=trow+1 statement. This should fix your problem.
(Also, for kicks, look up the Offset property in Excel VBE Help).
Matt
|