I have the following script working to lookup a value from column F and display it's matching value from column I in a message box, but ulyimately I need to send the resultValue to the default windows printer, and I'm not having much luck getting printing to work.
Here's the script:
I though this line would work, but I can't get it to work for the life of me:
ActiveWindow.resultValue.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
Here's the script:
VBA Code:
Sub LookupAndPrintToDefaultPrinter()
Dim searchValue As Variant
Dim ws As Worksheet
Dim searchRange As Range
Dim foundCell As Range
Dim resultValue As Variant
' Set the worksheet where you want to perform the search
Set ws = ThisWorkbook.Sheets("Main") ' Change "Sheet1" to your sheet's name
' Define the search range (column A in this example)
Set searchRange = ws.Columns("F") ' Change "A" to your desired column
' Ask user for input
searchValue = InputBox("Enter value to search:", "Lookup Value")
' Check if the user entered a value
If searchValue <> "" Then
' Look for the value in the search range
Set foundCell = searchRange.Find(searchValue, LookIn:=xlValues, LookAt:=xlWhole)
' If the value is found
If Not foundCell Is Nothing Then
' Get the value from a cell on the same row (column B in this example)
resultValue = ws.Cells(foundCell.Row, "I").Value ' Change "B" to your desired column
' Print the value to the default printer
MsgBox resultValue ' Print the value in the Immediate window (for demonstration purposes)
' To print to the default printer, you can use appropriate code here.
' For example, you might use the PrintOut method for the resultValue or specific content.
' Please replace the Debug.Print line above with the appropriate print command for your specific printer configuration.
' ActiveWindow.resultValue.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
Else
MsgBox "Value not found.", vbExclamation, "Result"
End If
Else
MsgBox "No value entered.", vbExclamation, "Result"
End If
End Sub
I though this line would work, but I can't get it to work for the life of me:
ActiveWindow.resultValue.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False