Using Do Loops to copy data
Wonderful, perfect.. This was just what I was looking for.
So, now that this has been provided to me, I am finding I am unable to alter
the code to do what else I need it too.
What I am ultimately looking to happen is this:
It scans down the column €śC€ť looking for €śAgent Name:€ť then grabbing the
name one column to the right and making a new sheet from that name. There
will be approximately 15 names.
Additionally, I need the sheet to grab each line between two names and copy
that information to the new sheet. The hook that will tell us that the line
needs to be copied is in column A and will contain a date (The date is not
static, but will always be in this format mm/dd/yyyy)
If anyone can further help me, I would be most appreciative.
"Dave Peterson" wrote:
Sometimes, just using Edit|Find (in code) will make things quicker:
Option Explicit
Sub testme()
Dim FoundCell As Range
Dim wks As Worksheet
Dim tName as String
Set wks = ActiveSheet
With wks
With .Range("C:C")
Set FoundCell = .Cells.Find(What:="Agent Name:", _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
End With
If FoundCell Is Nothing Then
MsgBox "Total not found in column C!"
Exit Sub
End If
tName = foundcell.offset(0,1).value
msgbox tname
End With
End Sub
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
--
Dave Peterson
|