Select a cell value of a workbook in another workbook

holy_eti

New Member
Joined
Jun 5, 2018
Messages
38
Hi, I would like to know if there was a possibility to Select the value of a Workbook in a Second Workbook using VBA.
I don't have any code for that, I am starting from blank and still am blank. In more details, I have a certain value in a Workbook lets take "1234" as example int the range ("B67"). I would love with VBA to be able to Select that same Value in another workbook with VBA. I've found the function Cells.Find but can't do nothing with it because the result I get is a boolean value. I would like to be able to find the range of that second value. As an example, my value "1234" is in range"B67" for my first workbook. In my second workbook, the same value "1234" is in range"B34". I would like to know if there was any possibilities that VBA could analyse both of my workbooks and give me the answer that "1234" is in range"B34".

Please note that english is not my first language so there might be some mistakes in my post.

Thank you,
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Code:
Dim foundCell as Range

Set FoundCell = Workbooks("Workbook2.xlsm").Worksheets("Sheet1").Cells.Find(what:=1234)

If FoundCell is Nothing then
    MsgBox "not found"
Else
    MsgBox "1234 was found in " & foundCell.Address(,,,True)
End IF
 
Upvote 0
Thank you for the quick answer. I sadly have an error 9: Subscript out of range when I arive to the line of Set foundCell = ....
here's with i have done so far

Code:
Private Sub CommandButton1_Click()


Dim annee, mois, jour, valeur, recherche As Variant
Dim nb_ligne, nb_ligne2, nb_ligne3, nb_ligne_nouveau As Integer


annee = TextBox1.Value
mois = TextBox2.Value
jour = TextBox3.Value


Application.ScreenUpdating = False


'Ouvrir le dernier Workbook sauvegardé et copier ses données
classeur = "\\Nasqcrf01\groupes\(Secteur_Sante-Securite\PSM\MOC\eMOC\Suivis\3. MOC scellés de sécurité (CSC-CSO)\Registre des MC\Archives\" & annee & "." & mois & "." & jour & ".xlsx"
classeur2 = annee & "." & mois & "." & jour & ".xlsm"
ThisWorkbook.Activate
nb_ligne = Range("C4").Value + 8
nb_ligne2 = Range("C4").Value + 2
nb_ligne3 = Range("C4").Value


valeur = Cells(nb_ligne, "C")


Workbooks.Open Filename:= _
        classeur
Sheets("Rapport sur la liste des activi").Activate
Sheets("Rapport sur la liste des activi").Range("B3").Select
    Range(Selection, Selection.End(xlDown)).Select
nb_ligne_nouveau = Selection.Rows.Count


Dim foundCell As Range


Set foundCell = Workbooks(classeur).Worksheets("Rapport sur la liste des activi").Cells.Find(what:=valeur)


If foundCell Is Nothing Then
    MsgBox "not found"
Else
    MsgBox (valeur & " was found in " & foundCell.Address(, , , True))
End If

End sub
 
Last edited:
Upvote 0
Found my mistake, for a reason that I ignore, the set option didnt like the call of my workbook and worksheet. Just had to activate them before and take them out of the set option and everything worked fine, again, thank you!
 
Upvote 0

Forum statistics

Threads
1,214,601
Messages
6,120,467
Members
448,965
Latest member
grijken

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