ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro / VBA for Find (https://www.excelbanter.com/excel-programming/386667-macro-vba-find.html)

Gary

Macro / VBA for Find
 
Is it possible to write a macro or code so that value placed in a cell could
be found over all tabs?

For example, if I place a value in cell D5, could I have the code behind a
button that would searche for whatever value is in D5 over all tabs?

Thanks.

Mike

Macro / VBA for Find
 
Try this

Sub cellvalues()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.Select
MsgBox ("Cell D5 in " & ws.Name & " value is " _
& ActiveSheet.Cells(5, 4).Value)
Next ws
End Sub

Is that any good?

Mike

"Gary" wrote:

Is it possible to write a macro or code so that value placed in a cell could
be found over all tabs?

For example, if I place a value in cell D5, could I have the code behind a
button that would searche for whatever value is in D5 over all tabs?

Thanks.


papou

Macro / VBA for Find
 
Hello Gary

'1-code behind your button:
Private Sub CommandButton1_Click()
ValuesFoundInD5
End Sub

'2-code in a new module:

Sub ValuesFoundInD5()
Dim sh As Worksheet
Dim TheValueinD5$
For Each sh In Sheets
If sh.[D5] < "" Then
TheValueinD5 = TheValueinD5 & vbLf & "Value " & sh.[D5] & " found in " &
sh.Name
End If
Next sh

Select Case TheValueinD5
Case Is < ""
MsgBox "This is the result:" & vbLf & TheValueinD5, vbInformation
Case Else
MsgBox "No value was found in cell D5 in this workbook", vbInformation
End Select
End Sub

HTH
Regards
Pascal

"Gary" a écrit dans le message de news:
...
Is it possible to write a macro or code so that value placed in a cell
could
be found over all tabs?

For example, if I place a value in cell D5, could I have the code behind a
button that would searche for whatever value is in D5 over all tabs?

Thanks.





All times are GMT +1. The time now is 05:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com