Pull info from one sheet to another

muzzy

Active Member
Joined
Apr 8, 2014
Messages
333
I am trying to use a vb that I have all ready I need to pull info from this sheet. and put it on another sheet. The info I need is Agent Name cell b1, Date cells b3 and b17, and the totals m15, and m30. I also have the end results for you to see. Below you will see the sheet and the VB I was trying to use. Can someone please help.

ABCDEFGHIJKLMN
1Agent: 50336 Adrovel, Mayra
2
3Date: 5/13/15
4
5Scheduled ActivitiesScheduled TimeActual TimeMin. in AdherenceMin. out AdherencePercent in Adherence+/- Min. in Conformance
6
7
8AUX 00:000:01000.00%1
9AUX 1: Break0:150:140150.00%-1
10AUX 3: Meeting0:000:39000.00%39
11AUX 8:Special Projec2:003:31952579.17%91
12
13Logoff4:304:35267398.89%5
14Logon2:150:0001350.00%-135
15Total9:009:0036217867.04%
0
16
17Date: 5/19/15
18
19Scheduled ActivitiesScheduled TimeActual TimeMin. in AdherenceMin. out AdherencePercent in Adherence+/- Min. in Conformance
20
21
22AUX 00:000:01000.00%1
23AUX 1: Break0:150:39150100.00%24
24AUX 2: Lunch1:000:000600.00%-60
25AUX 8:Special Projec0:003:45000.00%225
26
27Logoff4:154:352401594.12%20
28 Adherence
29Logon3:300:0002100.00%-210
30Total9:009:0025528547.22%
0
31
32Total for 50336 Adrovel, Mayra
33
34
35Scheduled ActivitiesScheduled TimeActual TimeMin. in AdherenceMin. out AdherencePercent in Adherence+/- Min. in Conformance

<colgroup><col span="16"></colgroup><tbody>
</tbody>



vba coding

Code:
Sub REPORT()
    For MY_ROWS = 1 To Range("C" & Rows.Count).End(xlUp).Row
        If Not (IsEmpty(Range("C" & MY_ROWS).Value)) Then
            MY_AGENT = Right(Range("C" & MY_ROWS).Value, Len(Range("C" & MY_ROWS).Value) - 7)
            For MY_NEXT_ROWS = MY_ROWS + 1 To Range("C" & MY_ROWS).End(xlDown).Row
                If Left(Range("D" & MY_NEXT_ROWS).Value, 4) = "Date" Then
                    MY_DATE = Right(Range("D" & MY_NEXT_ROWS).Value, Len(Range("D" & MY_NEXT_ROWS).Value) - 12)
                    MY_ACTIVITY = Range("D" & MY_NEXT_ROWS + 1).Offset(4, 4).Value
                    MY_LENGTH = Range("D" & MY_NEXT_ROWS + 1).Offset(12, 12).Value
                    With Sheets("Sheet2")
                        .Range("D" & Rows.Count).End(xlUp).Offset(1, 0).Value = MY_AGENT
                        .Range("E" & Rows.Count).End(xlUp).Offset(1, 0).Value = MY_DATE
                        .Range("F" & Rows.Count).End(xlUp).Offset(1, 0).Value = MY_ACTIVITY
                        .Range("G" & Rows.Count).End(xlUp).Offset(1, 0).Value = MY_LENGTH
                    End With
                End If
            Next MY_NEXT_ROWS
        End If
    Next MY_ROWS
End Sub


The End result:

Agent
DateScore
50336 Adrovel, Mayra 5/13/1567.04%
50336 Adrovel, Mayra 5/13/1547.22%

<colgroup><col><col><col></colgroup><tbody>
</tbody>
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Code:
Sub maybe()

    Const str_AGENT_AND_DATE_FIELD_IDENTIFIER As String = "Agent: "
    Const str_WANTED_PERCENTAGES_FIELD_IDENTIFIER As String = "Percent in Adherence"
    Const str_DATE_IDENTIFIER As String = "Date: "
    Const str_TOTAL_IDENTIFIER As String = "Total"

    Dim i As Long, k As Long
    Dim lng_Agent_and_Date_Column As Long
    Dim lng_Percentages_Column As Long
    
    Dim lng_Current_Agent_Row As Long
    Dim lng_Current_Date_Row As Long
    

    Dim wks As Excel.Worksheet
    

    Dim arIn As Variant
    Dim arOut(1 To 20000, 1 To 3) As Variant
    

    Set wks = ActiveSheet
    

    lng_Agent_and_Date_Column = wks.Cells.Find(What:=str_AGENT_AND_DATE_FIELD_IDENTIFIER, LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows).Column
    lng_Percentages_Column = wks.Cells.Find(What:=str_WANTED_PERCENTAGES_FIELD_IDENTIFIER).Column

    
    arIn = wks.UsedRange.Value
    Set wks = Nothing
    

    k = 1
    arOut(k, 1) = "Agent"
    arOut(k, 2) = "Date"
    arOut(k, 3) = "Score"
    

    For i = LBound(arIn, 1) To UBound(arIn, 1)
        If Left$(arIn(i, lng_Agent_and_Date_Column), 7) = str_AGENT_AND_DATE_FIELD_IDENTIFIER Then lng_Current_Agent_Row = i
        If Left$(arIn(i, lng_Agent_and_Date_Column), 6) = str_DATE_IDENTIFIER Then lng_Current_Date_Row = i
        If arIn(i, lng_Agent_and_Date_Column) = str_TOTAL_IDENTIFIER Then
            k = k + 1
            arOut(k, 1) = Mid$(arIn(lng_Current_Agent_Row, lng_Agent_and_Date_Column), 8, 255)
            arOut(k, 2) = Mid$(arIn(lng_Current_Date_Row, lng_Agent_and_Date_Column), 7, 255)
            arOut(k, 3) = arIn(i, lng_Percentages_Column)
        End If
    Next i
    Erase arIn

    
    With Worksheets("Sheet2")
        .Range("A1").CurrentRegion.Clear
        .Range("A1").Resize(k, 3).Value = arOut
        .Columns("B").NumberFormat = "m/d/yy"
        .Columns("C").NumberFormat = "00.00%"
    End With
    Erase arOut

End Sub
 
Upvote 0
Code:
Sub maybe()

    Const str_AGENT_AND_DATE_FIELD_IDENTIFIER As String = "Agent: "
    Const str_WANTED_PERCENTAGES_FIELD_IDENTIFIER As String = "Percent in Adherence"
    Const str_DATE_IDENTIFIER As String = "Date: "
    Const str_TOTAL_IDENTIFIER As String = "Total"

    Dim i As Long, k As Long
    Dim lng_Agent_and_Date_Column As Long
    Dim lng_Percentages_Column As Long
    
    Dim lng_Current_Agent_Row As Long
    Dim lng_Current_Date_Row As Long
    

    Dim wks As Excel.Worksheet
    

    Dim arIn As Variant
    Dim arOut(1 To 20000, 1 To 3) As Variant
    

    Set wks = ActiveSheet
    

    lng_Agent_and_Date_Column = wks.Cells.Find(What:=str_AGENT_AND_DATE_FIELD_IDENTIFIER, LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows).Column
    lng_Percentages_Column = wks.Cells.Find(What:=str_WANTED_PERCENTAGES_FIELD_IDENTIFIER).Column

    
    arIn = wks.UsedRange.Value
    Set wks = Nothing
    

    k = 1
    arOut(k, 1) = "Agent"
    arOut(k, 2) = "Date"
    arOut(k, 3) = "Score"
    

    For i = LBound(arIn, 1) To UBound(arIn, 1)
        If Left$(arIn(i, lng_Agent_and_Date_Column), 7) = str_AGENT_AND_DATE_FIELD_IDENTIFIER Then lng_Current_Agent_Row = i
        If Left$(arIn(i, lng_Agent_and_Date_Column), 6) = str_DATE_IDENTIFIER Then lng_Current_Date_Row = i
        If arIn(i, lng_Agent_and_Date_Column) = str_TOTAL_IDENTIFIER Then
            k = k + 1
            arOut(k, 1) = Mid$(arIn(lng_Current_Agent_Row, lng_Agent_and_Date_Column), 8, 255)
            arOut(k, 2) = Mid$(arIn(lng_Current_Date_Row, lng_Agent_and_Date_Column), 7, 255)
            arOut(k, 3) = arIn(i, lng_Percentages_Column)
        End If
    Next i
    Erase arIn

    
    With Worksheets("Sheet2")
        .Range("A1").CurrentRegion.Clear
        .Range("A1").Resize(k, 3).Value = arOut
        .Columns("B").NumberFormat = "m/d/yy"
        .Columns("C").NumberFormat = "00.00%"
    End With
    Erase arOut

End Sub

Thanks but it does not work all I get on sheet2 is Agent, Date and Score. on the page as a title. I know I have been try to get this for about week and a half now. If you can help thank you.
 
Upvote 0

Forum statistics

Threads
1,215,284
Messages
6,124,059
Members
449,139
Latest member
sramesh1024

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