Macro to find value, select cell and print selected cell

DB38

New Member
Joined
Mar 22, 2023
Messages
7
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Good morning
I'm looking for somebody who can help me with below.

In row (1:1) i have cells containing a image and a barcode nr 87.....
The idea is that i have a scanner that scan a 87.... barcode in an window.
The marco should look up this value in row (1:1) if the unique cell is found (and selected) i.e D1 then the active selected cell should be printed.


Hope anyone can help me with this.
Thanks in advance.

Din
 

Attachments

  • 2023-03-22_08h20_17.jpg
    2023-03-22_08h20_17.jpg
    124.3 KB · Views: 8

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Hi,
Have you tried to turn on your macro recorder and go through an example ... to see the "VBA-translation" of your actions ...
 
Upvote 0
Hi
Looks something like this. The find value I have put in cell A2 for now.

----------

Sub Macro2()
'
' Macro2 Macro
'

'
Cells.Find(What:="871976947833", After:=ActiveCell, LookIn:=xlFormulas2 _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Selection.PrintOut Copies:=1, Collate:=True
End Sub
 
Upvote 0
Hi again,
You could test following and adjust code to your needs :
VBA Code:
Function myFind(st As String)
' UDF to get the Address in Row 1
' which holds the searched string
  Dim rng As Range
  Set rng = Rows("1:1").Find(st)
  ' Print Found range
  'rng.PrintOut
  myFind = rng.Address(0, 0)
End Function
 
Upvote 0
Thanks for your help. Sorry but I'm far from expert.
Where in the code should i change to look in cell A2 ?
 
Upvote 0
Hi,
Sorry ... should have explained ... in cell A2, just type :

Excel Formula:
=myFind("871976947833")
 
Upvote 0
Could it be that the myfind function is unknown, and the A2 value is not static. If i change the cell info it should go to another cell in row 1 to print
 
Upvote 0
Hi again,
No comment on you result for the UDF ...
You could test the following macro :
VBA Code:
Sub PrintLabel()
Dim st As String, rng As Range
  ' Ask for Barcode to be serached in Row 1
  ' 12 Character Input such as : 871976947833
  st = InputBox("Please scan a barcode and hit enter if you need to")
  ' Find the Address in Row 1
  Set rng = Rows("1:1").Find(st)
  ' Print Found Range
  rng.PrintOut
End Sub
 
Upvote 0
ohw whauw, this looks good !!! Thanks test on again on monday.
After printing i need to go back to the input box, can you add the code for this ?
Thanks a million !!!
Din
 
Upvote 0

Forum statistics

Threads
1,214,944
Messages
6,122,387
Members
449,080
Latest member
Armadillos

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