Consulting

Page 1 of 2 1 2 LastLast
Results 1 to 20 of 28

Thread: Solved: Data_from_another_Spreadsheet

  1. #1
    VBAX Tutor
    Joined
    Jan 2011
    Posts
    272
    Location

    Solved: Data_from_another_Spreadsheet

    Hi.

    I need to return data from worksheet named 'Compras' based cell 'K2' spreadsheet 'Ordem_Compra'

    the problem is I can not change the the appearance of the spreadsheet 'Compras'
    Attached Files Attached Files

  2. #2
    VBAX Tutor PAB's Avatar
    Joined
    Nov 2011
    Location
    London (UK)
    Posts
    243
    Location
    Hi marreco,

    What data do you want to transfer from the Worksheet named 'Compras', what cells or range, and where to you want it to go in the Worksheet named 'Ordem_Compra'?

    Regards,
    PAB
    -----------------------------------------∏-

    12:45, restate my assumptions.
    Mathematics is the language of nature.
    Everything around us can be represented and understood through numbers.
    If you graph the numbers of any system, patterns emerge. Therefore, there are patterns everywhere in nature.

    -----------------------------------------∏-

  3. #3
    VBAX Tutor
    Joined
    Jan 2011
    Posts
    272
    Location
    Hi.
    to enter in the worksheet 'Ordem_Compra' the number '2 ' (Cell K2)is returned then the spreadsheet data 'Compras'

    See the line with the number '2 'in the worksheet 'Compras'

    my attachment was all done manually

  4. #4
    VBAX Tutor PAB's Avatar
    Joined
    Nov 2011
    Location
    London (UK)
    Posts
    243
    Location
    Hi marreco,

    Do you mean something like this?
    Copy and paste this into any cell in the Worksheet named 'Ordem_Compra'.

    [vba]
    =Compras!K2 [/vba]
    Regards,
    PAB
    -----------------------------------------∏-

    12:45, restate my assumptions.
    Mathematics is the language of nature.
    Everything around us can be represented and understood through numbers.
    If you graph the numbers of any system, patterns emerge. Therefore, there are patterns everywhere in nature.

    -----------------------------------------∏-

  5. #5
    VBAX Tutor
    Joined
    Jan 2011
    Posts
    272
    Location
    Hi.
    is in the worksheet 'Ordem_Compra'
    but according to the data

    look at my attachment and better understand

  6. #6
    VBAX Tutor PAB's Avatar
    Joined
    Nov 2011
    Location
    London (UK)
    Posts
    243
    Location
    Hi marreco,

    You want "K2" in the Worksheet named 'Ordem_Compra' copied to where in the Worksheet named 'Compras'?

    Regards,
    PAB
    -----------------------------------------∏-

    12:45, restate my assumptions.
    Mathematics is the language of nature.
    Everything around us can be represented and understood through numbers.
    If you graph the numbers of any system, patterns emerge. Therefore, there are patterns everywhere in nature.

    -----------------------------------------∏-

  7. #7
    VBAX Tutor
    Joined
    Jan 2011
    Posts
    272
    Location
    Hi.
    yes!

    But it has to be automatic.

    If I enter another númeor in 'K2'

  8. #8
    VBAX Tutor PAB's Avatar
    Joined
    Nov 2011
    Location
    London (UK)
    Posts
    243
    Location
    Hi marreco,

    Copy and paste this into the cell in the Worksheet named 'Compras'.

    [VBA]
    =Ordem_Compra!K2 [/VBA]
    Regards,
    PAB
    -----------------------------------------∏-

    12:45, restate my assumptions.
    Mathematics is the language of nature.
    Everything around us can be represented and understood through numbers.
    If you graph the numbers of any system, patterns emerge. Therefore, there are patterns everywhere in nature.

    -----------------------------------------∏-

  9. #9
    VBAX Tutor
    Joined
    Jan 2011
    Posts
    272
    Location
    Hi.
    Not so!!!!!
    imagine you are in the worksheet 'Ordem_Compra'

    then 'K2' you type the number '9 '

    In 'C3' will return 'Bebeto'

    In 'C4' will return 'FornNumb_3221'

    In 'B9' will return 'Laptop'
    In 'F9' will return 'Unidade'
    In 'H9' is returned '9 '
    In 'I9' is returned '777 '

  10. #10
    VBAX Tutor PAB's Avatar
    Joined
    Nov 2011
    Location
    London (UK)
    Posts
    243
    Location
    Hi marreco,

    I am having a problem with your Workbook, I think it might be the language or version you are using so I will post the formulas to use.

    In cell C3.
    [vba]=VLOOKUP($K$2,Compras!$A$3:$AR$27,4)[/vba]
    In cell C4.
    [vba]=VLOOKUP($K$2,Compras!$A$3:$AR$27,3)[/vba]
    In cell B9.
    [vba]=VLOOKUP($K$2,Compras!$A$3:$AR$27,5)[/vba]
    In cell F9.
    [vba]=VLOOKUP($K$2,Compras!$A$3:$AR$27,6)[/vba]
    In cell H9.
    [vba]=VLOOKUP($K$2,Compras!$A$3:$AR$27,7)[/vba]
    In cell I9.
    [vba]=VLOOKUP($K$2,Compras!$A$3:$AR$27,8)[/vba]
    I hope this helps!

    Regards,
    PAB
    -----------------------------------------∏-

    12:45, restate my assumptions.
    Mathematics is the language of nature.
    Everything around us can be represented and understood through numbers.
    If you graph the numbers of any system, patterns emerge. Therefore, there are patterns everywhere in nature.

    -----------------------------------------∏-

  11. #11
    VBAX Tutor
    Joined
    Jan 2011
    Posts
    272
    Location
    Hi.
    PAB can do this with VBA?

    I need via MACRO!

    Thank you!!!

  12. #12
    VBAX Tutor PAB's Avatar
    Joined
    Nov 2011
    Location
    London (UK)
    Posts
    243
    Location
    Hi marreco,

    Do the formulas NOT work then?

    Regards,
    PAB
    -----------------------------------------∏-

    12:45, restate my assumptions.
    Mathematics is the language of nature.
    Everything around us can be represented and understood through numbers.
    If you graph the numbers of any system, patterns emerge. Therefore, there are patterns everywhere in nature.

    -----------------------------------------∏-

  13. #13
    VBAX Tutor
    Joined
    Jan 2011
    Posts
    272
    Location
    works well!
    the problem 'that my project needs to be based on MACRO.

    could you help me?

    Thank you!

  14. #14
    VBAX Tutor PAB's Avatar
    Joined
    Nov 2011
    Location
    London (UK)
    Posts
    243
    Location
    Is this a school or work project?
    -----------------------------------------∏-

    12:45, restate my assumptions.
    Mathematics is the language of nature.
    Everything around us can be represented and understood through numbers.
    If you graph the numbers of any system, patterns emerge. Therefore, there are patterns everywhere in nature.

    -----------------------------------------∏-

  15. #15
    VBAX Tutor
    Joined
    Jan 2011
    Posts
    272
    Location
    I had trouble for having formulas in the worksheet because users ended up having to change and for not practicing, did anything wrong.

    so I decided to use VBA.

  16. #16
    VBAX Tutor PAB's Avatar
    Joined
    Nov 2011
    Location
    London (UK)
    Posts
    243
    Location
    Hi marreco,

    Here you go!

    [vba]Option Explicit
    Sub Retrieve_Data()
    With Application
    .ScreenUpdating = False: .Calculation = xlCalculationManual: .DisplayAlerts = False
    End With
    With Sheets("Ordem_Compra").Select
    Range("C3:C4, B9:J18").ClearContents
    Range("C3").Value = Evaluate("=VLOOKUP($K$2,Compras!$A$3:$AR$27,4)")
    Range("C4").Value = Evaluate("=VLOOKUP($K$2,Compras!$A$3:$AR$27,3)")
    Range("B9").Value = Evaluate("=VLOOKUP($K$2,Compras!$A$3:$AR$27,5)")
    Range("F9").Value = Evaluate("=VLOOKUP($K$2,Compras!$A$3:$AR$27,6)")
    Range("H9").Value = Evaluate("=VLOOKUP($K$2,Compras!$A$3:$AR$27,7)")
    Range("I9").Value = Evaluate("=VLOOKUP($K$2,Compras!$A$3:$AR$27,8)")
    End With
    With Application
    .DisplayAlerts = True: .Calculation = xlCalculationAutomatic: .ScreenUpdating = True
    End With
    End Sub[/vba]
    You still didn't say whether this is a school or work project?
    Let me know how this works.

    Regards,
    PAB
    -----------------------------------------∏-

    12:45, restate my assumptions.
    Mathematics is the language of nature.
    Everything around us can be represented and understood through numbers.
    If you graph the numbers of any system, patterns emerge. Therefore, there are patterns everywhere in nature.

    -----------------------------------------∏-

  17. #17
    VBAX Tutor
    Joined
    Jan 2011
    Posts
    272
    Location
    Hi.
    I needed to use automatically run without a button.

    How do I work through Sub Worksheet_Change (ByVal Target As Range)?


    You still didn't say whether this is a school or work project?
    Let me know how this works.
    Use in my work

  18. #18
    VBAX Tutor PAB's Avatar
    Joined
    Nov 2011
    Location
    London (UK)
    Posts
    243
    Location
    Hi marreco,

    Put this code in Sheet1(Ordem_Compra).

    [vba]Sub Worksheet_Change(ByVal Target As Range)
    With Application
    .ScreenUpdating = False: .Calculation = xlCalculationManual:
    .EnableEvents = False: .DisplayAlerts = False
    End With
    With Sheets("Ordem_Compra").Select
    Range("C3:C4, B9:J18").ClearContents
    Range("C3").Value = Evaluate("=VLOOKUP($K$2,Compras!$A$3:$AR$27,4)")
    Range("C4").Value = Evaluate("=VLOOKUP($K$2,Compras!$A$3:$AR$27,3)")
    Range("B9").Value = Evaluate("=VLOOKUP($K$2,Compras!$A$3:$AR$27,5)")
    Range("F9").Value = Evaluate("=VLOOKUP($K$2,Compras!$A$3:$AR$27,6)")
    Range("H9").Value = Evaluate("=VLOOKUP($K$2,Compras!$A$3:$AR$27,7)")
    Range("I9").Value = Evaluate("=VLOOKUP($K$2,Compras!$A$3:$AR$27,8)")
    End With
    With Application
    .DisplayAlerts = True: .EnableEvents = True:
    .Calculation = xlCalculationAutomatic: .ScreenUpdating = True
    End With
    End Sub[/vba]
    Regards,
    PAB
    -----------------------------------------∏-

    12:45, restate my assumptions.
    Mathematics is the language of nature.
    Everything around us can be represented and understood through numbers.
    If you graph the numbers of any system, patterns emerge. Therefore, there are patterns everywhere in nature.

    -----------------------------------------∏-

  19. #19
    VBAX Mentor Teeroy's Avatar
    Joined
    Apr 2012
    Location
    Sydney, Australia
    Posts
    414
    Location
    Hi marreco,

    PAB's code should meet your requirements but will put some (quite small) processing overhead on the PC as it runs every time there's a change to any cell on the sheet. Is there any reason why you couldn't just use formula's (per PAB #10), unlock only the data entry cells, and password protect the sheet?
    _________________________________________________________________________
    "In theory there is no difference between theory and practice. In practice there is." - Chuck Reid

    Any day you learn something new is a day not wasted.

  20. #20
    VBAX Tutor
    Joined
    Jan 2011
    Posts
    272
    Location
    Hi.
    I had to change the formula.
    I can help reduce large as the code and make it work?
    Thank you!

    [VBA]Sub Worksheet_Change(ByVal Target As Range)
    With Application
    .ScreenUpdating = False: .Calculation = xlCalculationManual:
    .EnableEvents = False: .DisplayAlerts = False
    End With
    With Sheets("Ordem de Compra").Select
    Range("C3:C4, B9:J18").ClearContents
    Range("C3").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),4),"""")")
    Range("C4").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),3),"""")")

    Range("B9").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),5),"""")")
    Range("F9").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),6),"""")")
    Range("H9").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),7),"""")")
    Range("I9").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),8),"""")")

    Range("B10").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),9),"""")")
    Range("F10").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),10),"""")")
    Range("H10").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),11),"""")")
    Range("I10").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),12),"""")")

    Range("B11").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),13),"""")")
    Range("F11").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),14),"""")")
    Range("H11").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),15),"""")")
    Range("I11").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),16),"""")")

    Range("B12").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),17),"""")")
    Range("F12").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),18),"""")")
    Range("H12").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),19),"""")")
    Range("I12").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),20),"""")")

    Range("B13").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),20),"""")")
    Range("F13").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),21),"""")")
    Range("H13").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),22),"""")")
    Range("I13").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),23),"""")")

    Range("B14").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),24),"""")")
    Range("F14").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),25),"""")")
    Range("H14").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),26),"""")")
    Range("I14").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),27),"""")")

    Range("B15").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),28),"""")")
    Range("F15").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),29),"""")")
    Range("H15").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),30),"""")")
    Range("I15").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),31),"""")")

    Range("B16").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),32),"""")")
    Range("F16").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),33),"""")")
    Range("H16").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),34),"""")")
    Range("I16").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),35),"""")")

    Range("B17").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),36),"""")")
    Range("F17").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),37),"""")")
    Range("H17").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),38),"""")")
    Range("I17").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),39),"""")")

    Range("B18").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),40),"""")")
    Range("F18").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),41),"""")")
    Range("H18").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),42),"""")")
    Range("I18").Value = Evaluate("=IFERRO(INDEX(Compras!$A$3:$AR$27,MATCH($K$2,Compras!$A$3:$A$27,0 ),43),"""")")



    End With
    With Application
    .DisplayAlerts = True: .EnableEvents = True:
    .Calculation = xlCalculationAutomatic: .ScreenUpdating = True
    End With
    End Sub[/VBA]

    Cross-Post
    http://www.mrexcel.com/forum/excel-q...rize-code.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •