Do untill command

Adrac

Active Member
Joined
Feb 13, 2014
Messages
280
Office Version
  1. 365
Platform
  1. Windows
Hello all,

I have a macro that looks in A and finds a name, then finds a word of text in a cell the copies information.
I would like it to keep finding the word cells until it reaches another word cell:

Example:

Code:
Cells.Find(What:="Bob", After:=ActiveCell).Activate
Cells.Find(What:="Inbound", After:=ActiveCell).Activate
ActiveCell.Offset(0, 2).Range("A1").Copy
ActiveCell.Offset(0, 16).Range("A1").Select
ActiveSheet.Paste
***this ia where i want it to go to***
do this command above until it finds the word 'Wrokgroup' in a cell then next command (person)

Can anyone help?

Adrac
 
ok i can see what it doers however still not bring me any results. but then im not sure what its doing lol
and as for the other sheet what it was doing is finding the Name on row 3 then finding the date in column A and entering in the results.
i had this as a part of the macro: can this be intigrated into the script?

Code:
 Dim dt As Date
dt = WorksheetFunction.WorkDay(Date, -1)
Columns("A:A").Select
    Range("A1").Activate
    Selection.Find(What:=dt, After:=ActiveCell, LookIn:=xlFormulas _
    , LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False).Select
ActiveCell.Offset(0, 1).Select
 
Upvote 0

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Excellent this is more like it, thank you. Can i add a command so i can see what its doing as im not getting any results or to tailor make it please?</SPAN>

You should be able to step through the code and watch what it is doing. You can also add msgbox code in spots to determine what certain values are at certain points. Finally, I will give you more indication in some very similar code (slightly improved because I hadn't used arrays in so long)

Code:
Option Explicit
Sub Inbound()
Dim nBnd As Double, x As Integer
Dim Rng As Range, CE1 As Range, Rw As Range, CE2 As Range
Dim RcrdSh As Worksheet, DtSh As Worksheet
Dim RcrdWb As Workbook, DtWb As Workbook
Dim NameA() As Variant 'There is no reason to adjust this piece any longer

'The following fills the NameA array of variant length based on how many etries you make
NameA() = Array("Baker, Bob", _
    "Barnes, Kim", _
    "Davies, Nick", _
    "Bryant, Nick", _
    "Davies, James", _
    "Thomas, CJ", _
    "Thompson, Reggie")
' in this case there are 7 entries into the array stipulated as 0 to 6

'Following determines where you will record the data
Set RcrdWb = Workbooks("Results.xlsx") 'adjust to workbook to which you are recording
Set RcrdSh = RcrdWb.Worksheets("Sheet1") 'likewise with workbook you are getting data from

'Following determines where you will get the data from
Set DtWb = Workbooks("data.xlsx") ' adjust to sheet name of the recording workbook
Set DtSh = DtWb.Worksheets("Sheet1") 'and sheet you will be getting it from

'The for loop goes through the array 0 to last entry in the Array NameA
For x = 0 To UBound(NameA) 'First name assigns to 0 so 0 to 1 less than count you have
    'Find the first instance of the array that you are on at the end of a cell in column A
    Set CE1 = DtSh.Range("A:A").Find("*" & NameA(x), After:=Cells(1, 1))
    'If The name is found
    If Not CE1 Is Nothing Then
        'Find the next instance (after found name) where workgroup starts a cell in column A
        Set Rw = DtSh.Range(CE1, DtSh.Cells(Rows.Count, "A").End(xlUp)).Find("Workgroup*", After:=CE1)
        'if there is not an instance found of workgroup then set Rw = to the last row in column A
        If Rw Is Nothing Then Set Rw = DtSh.Cells(Rows.Count, "A").End(xlUp)
        'Set a range from the found name to next instance of workgroup
        Set Rng = Range(CE1, Rw)
        'use worksheetfunction sumif to find instances where inbound starts the cell in set Rng and sum column C of those rows
        nBnd = Application.WorksheetFunction.SumIf(Rng, "inbound*", Rng.Offset(0, 2))
        'Find the first available row in column A of Record sheet
        Set CE2 = RcrdSh.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
        'Assign name to column A of next available row
        CE2 = NameA(x)
        'One cell to right enter Inbound
        CE2.Offset(0, 1) = "Inbound"
        'One cell to right of Inbound entry enter the value for all inbound calls
        CE2.Offset(0, 2) = nBnd
    End If
Next

End Sub
With the example data you provided this code returned 2 new lines in the Results.xlsx workbook on a sheet named Sheet1 for me.
 
Upvote 0
Great thanks Brian, i shall try this tomorrow when im back at work and ill let you know, thanks again for your help.
 
Upvote 0
Hello brian, im still not getting a result for this code, and still cant see what its doing even when i press F8 to go to next line. Can we make it so i can see what each line does, as this maybe too advanced for my wee brain to handle lol
I cant provide you with the actual document but i can give you detail information on what the data looks like with the names changed.

Thanks for your help
 
Upvote 0
i dont know if this helps, and like i say its differant every time. and i need the completed result
A BC
1Agent Management
2Report Generated at 09/04/2014 03:05:09 GMT by Schedule
3
4
5 Workgroup: <hidden>
6 User Name: bakera (Active)
7 Agent Name: Baker, Adam
8
9Interaction Type / Taken FromOriginatedCompleted
10Inbound Queued Call
11<N/A>11
12WAK01 Inbound1818
13WAK01 Inbound Overflow33
14WAK01 <hidden>ignore11
15Outbound Direct Call
16<N/A>22
17User Total:2525
18
19 Workgroup: WAK01 CRL-HS2
20 User Name: barnesk (Active)
21 Agent Name: Barnes, Kim
22
23Interaction Type / Taken FromOriginatedCompleted
24Inbound Queued Call
25WAK01 Inbound65
26WAK01 Inbound Overflow77
27Outbound Direct Call
28<N/A>2216
29User Total:3528
30 Workgroup: WAK01 CRL-HS2
31 User Name: daviesn (Active)
32 Agent Name: Davies, Nesh
ETC…..

<COLGROUP><COL style="WIDTH: 27pt; mso-width-source: userset; mso-width-alt: 1316" width=36><COL style="WIDTH: 167pt; mso-width-source: userset; mso-width-alt: 8155" width=223><COL style="WIDTH: 50pt; mso-width-source: userset; mso-width-alt: 2413" width=66><COL style="WIDTH: 52pt; mso-width-source: userset; mso-width-alt: 2523" width=69><TBODY>
</TBODY>
 
Upvote 0
Code:
Sub Inbound()
Dim nBnd As Double, x As Integer
Dim Rng As Range, CE1 As Range, Rw As Range, CE2 As Range
Dim RcrdSh As Worksheet, DtSh As Worksheet
Dim RcrdWb As Workbook, DtWb As Workbook
Dim NameA() As Variant

NameA() = Array("Baker, Bob", _
    "Barnes, Kim", _
    "Davies, Nick", _
    "Bryant, Nick", _
    "Davies, James", _
    "Thomas, CJ", _
    "Thompson, Reggie")

Set RcrdWb = Workbooks("Results.xlsx")
Set RcrdSh = RcrdWb.Worksheets("Sheet1")

Set DtWb = Workbooks("data.xlsx")
Set DtSh = DtWb.Worksheets("Sheet1")

For x = 0 To UBound(NameA)
    Set CE1 = DtSh.Range("A:A").Find("*" & NameA(x), After:=Cells(1, 1))
    Debug.Print "Name: " & NameA(x)
    If Not CE1 Is Nothing Then
        Debug.Print "Name Found: " & CE1.Address
        Set Rw = DtSh.Range(CE1, DtSh.Cells(Rows.Count, "A").End(xlUp)).Find("Workgroup*", After:=CE1)
        If Rw Is Nothing Then Set Rw = DtSh.Cells(Rows.Count, "A").End(xlUp)
        Set Rng = Range(CE1, Rw)
        nBnd = Application.WorksheetFunction.SumIf(Rng, "inbound*", Rng.Offset(0, 2))
        Set CE2 = RcrdSh.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
        Debug.Print "Row to Paste on: " & CE2.Address
        CE2 = NameA(x)
        CE2.Offset(0, 1) = "Inbound"
        CE2.Offset(0, 2) = nBnd
    End If
Next

End Sub
I added a few lines of debug.print (removed the comments because I figure you have the commented code at this point and it is just easier for me to work without it). I ran the code 2 times on the example data you gave me Altering it slightly each time without altering the results sheet. In the immediate window after the first run it debugged like this:

HTML:
Name: Baker, Bob
Name Found: $A$2
Row to Paste on: $A$2
Name: Barnes, Kim
Name Found: $A$12
Row to Paste on: $A$3
Name: Davies, Nick
Name: Bryant, Nick
Name: Davies, James
Name: Thomas, CJ
Name: Thompson, Reggie
on the second run:
HTML:
Name: Baker, Bob
Name: Barnes, Kim
Name Found: $A$2
Row to Paste on: $A$4
Name: Davies, Nick
Name: Bryant, Nick
Name: Davies, James
Name: Thomas, CJ
Name: Thompson, Reggie
Name Found: $A$12
Row to Paste on: $A$5
The result file looks like this:

Name Dir Ttl
Baker, Bob Inbound 18
Barnes, Kim Inbound 10
Barnes, Kim Inbound 18
Thompson, Reggie Inbound 10
 
Upvote 0
its finding the names but bringing back 0. i need to see where it is looking for it, to change it :(
 
Upvote 0
It appears I based things off the first set of data that I received but I see what we are running into with the 2nd set of data. It really wasn't an issue with where it was looking, but rather what the sumif was looking for. I had a crazy assumption that inbound would be always at the first of the cell, but that is not the case with the 2nd set of data. I then made the assumption that this may not be true of the Name always being at the end of a cell, nor the workgroup always beginning the cell. See if this works out better for you.

Code:
Sub Inbound()
Dim nBnd As Double, x As Integer
Dim Rng As Range, CE1 As Range, Rw As Range, CE2 As Range
Dim RcrdSh As Worksheet, DtSh As Worksheet
Dim RcrdWb As Workbook, DtWb As Workbook
Dim NameA() As Variant

NameA() = Array("Baker, Adam", _
    "Barnes, Kim", _
    "Davies, Nick", _
    "Bryant, Nick", _
    "Davies, James", _
    "Thomas, CJ", _
    "Thompson, Reggie")

Set RcrdWb = Workbooks("Results.xlsx")
Set RcrdSh = RcrdWb.Worksheets("Sheet1")

Set DtWb = Workbooks("data.xlsx")
Set DtSh = DtWb.Worksheets("Sheet1")

For x = 0 To UBound(NameA)
    Set CE1 = DtSh.Range("A:A").Find("*" & NameA(x) & "*", After:=Cells(1, 1))
    'Debug.Print "Name: " & NameA(x)
    If Not CE1 Is Nothing Then
        'Debug.Print "Name Found: " & CE1.Address
        Set Rw = DtSh.Range(CE1, DtSh.Cells(Rows.Count, "A").End(xlUp)).Find("*Workgroup*", After:=CE1)
        If Rw Is Nothing Then Set Rw = DtSh.Cells(Rows.Count, "A").End(xlUp)
        Set Rng = Range(CE1, Rw)
        nBnd = WorksheetFunction.SumIf(Rng, "*inbound*", Rng.Offset(0, 2))
        Set CE2 = RcrdSh.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
        'Debug.Print "Row to Paste on: " & CE2.Address
        CE2 = NameA(x)
        CE2.Offset(0, 1) = "Inbound"
        CE2.Offset(0, 2) = nBnd
    End If
Next

End Sub
 
Upvote 0
Eureka! i think you got it!! yay! heheh what ill do is get tomorrows data as it wont be in the same cells and see if it all works ok with that

Ok now we have the data how do i get this code in what you have already?
Code:
    Dim dt As Date
dt = WorksheetFunction.WorkDay(Date, -1)
Windows("Workbook 2014.xlsb").Activate
Sheets("Results").Select
    Columns("A:A").Select
    'Range("A1").Activate
    Selection.Find(What:=dt, After:=ActiveCell, LookIn:=xlFormulas _
    , LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False).Select
ActiveCell.Offset(0, 1).Select
  
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False


Thanks again BRian. ill be more clear next time lol
 
Upvote 0
Eureka! i think you got it!! yay! heheh what ill do is get tomorrows data as it wont be in the same cells and see if it all works ok with that

Ok now we have the data how do i get this code in what you have already?
Code:
    Dim dt As Date
dt = WorksheetFunction.WorkDay(Date, -1)
Windows("Workbook 2014.xlsb").Activate
Sheets("Results").Select
    Columns("A:A").Select
    'Range("A1").Activate
    Selection.Find(What:=dt, After:=ActiveCell, LookIn:=xlFormulas _
    , LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False).Select
ActiveCell.Offset(0, 1).Select
  
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False


Thanks again BRian. ill be more clear next time lol
No problem, we do the best with what we know. I understand that communication is a 2 way street and it very well could have been on my end.

Now I just want to make sure I understand what you are desiring for the next part. We have the value for total inbound in nBnd and you want that value, and I suppose the name we searched for in column B of the Results sheet that is located in Workbook 2014.xlsb, but it should be in a row that contains the date for yesterday? The only issue I see there is that we will overwrite the data continuously. How do you want that handled. Should the first write find yesterdays date and the subsequent find the next available row in column B ( or can it find the next available row always in column B)?
 
Upvote 0

Forum statistics

Threads
1,215,363
Messages
6,124,505
Members
449,166
Latest member
hokjock

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top