Consulting

Results 1 to 9 of 9

Thread: Finding the active cell in other work book

  1. #1
    VBAX Regular
    Joined
    Sep 2016
    Location
    CHENNAI
    Posts
    13
    Location

    Finding the active cell in other work book

    hi team,

    In my work, I have to copy the particular cells of active sheet (say Workbook 1), find in other workbook(say workbook 2)

    It is very time consuming to do this for every cell in the workbook 1

    I need a VBA code to assign a short cut Key, may be "Ctrl + E", to find the active cell in other work book

    If you think there is a better way of doing this, please let me know!

    Thanks in advance

  2. #2
    VBAX Expert
    Joined
    May 2016
    Posts
    604
    Location
    Try this
    Assuming you are in Book2 and the other book is book3
    [VBA]Dim tempadd As String


    Workbooks("Book3").Activate
    tempadd = ActiveCell.Address
    Workbooks("Book2").Activate
    MsgBox (tempadd)


    [/VBA]

    Note this appears to me to answer what you asked, but you haven't stated what you want to do with the address once you have found it.

  3. #3
    VBAX Regular
    Joined
    Sep 2016
    Location
    CHENNAI
    Posts
    13
    Location
    Thanx for the help but need some clarification...

    What wborkbook does "Book2" & "Book3" refers here...?

    like i need to find "E7" of Book 2 in Book3

    and also assign short cut key "Ctrl + E"

    Thanx

  4. #4
    VBAX Expert
    Joined
    May 2016
    Posts
    604
    Location
    Book2 is the name of the workbook you are currently in, Book3 in the name of the "other" workbook. I don't know the names of your workbooks so I used the excel default names.vthese could be the "Workbook 1" and "workbook 2" from you original question.

    What do you mean by "Find"

  5. #5
    VBAX Regular
    Joined
    Sep 2016
    Location
    CHENNAI
    Posts
    13
    Location
    "Ctrl + f" find command

    The whole thing is go to the active cell value in other work book not to get cell address.

    Ex:

    When I recorded the process it shows the code as


    Sub Macro1()

    Range("E12").Select
    Selection.Copy
    Windows("Book3.xlsx").Activate
    Cells.Find(What:="Tar pore", After:=ActiveCell, _
    LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
    SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
    End Sub



    The problem here is the macro sets "E12" as range where as i want the active cell of Book2 to be the range and also
    the find "What:="Tar pore" should also be the active cell value of Book2.


    Hope you understood
    Last edited by msahmed; 09-08-2016 at 12:41 PM.

  6. #6
    VBAX Expert
    Joined
    May 2016
    Posts
    604
    Location
    That is much clearer :
    try this;

    [vba]Sub test()
    Dim findstr As String


    findstr = ActiveCell.Value


    Workbooks("book3").Activate
    Cells.Find(What:=findstr, After:=ActiveCell, _
    LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
    SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
    End Sub
    [/vba]

    I forgot to say to assign a control key to the macro go to macros on the tab then select this macro and then options and asign the control key

  7. #7
    VBAX Regular
    Joined
    Sep 2016
    Location
    CHENNAI
    Posts
    13
    Location
    That works great...:-)

    Thanks again...

  8. #8
    VBAX Regular
    Joined
    Sep 2016
    Location
    CHENNAI
    Posts
    13
    Location
    Hi there,

    Is there any way with copied value to get find. Like if i copied the data from other source, say pdf.

  9. #9
    VBAX Expert
    Joined
    May 2016
    Posts
    604
    Location
    Try this instead of the activecell value: ( I haven't tested it) also you will need to add a reference to Microsoft Forms 2.0. Object library in the VBA refences, ( go to Tools references inthe VBa windos and click the refence as required

    [vba] Dim objData As New MSForms.DataObject
    Dim Findstr as string


    objData.GetFromClipboard
    findstr = objData.GetText()


    [/vba]

Tags for this Thread

Posting Permissions

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