VBA for Macro Button

nathanthomson11

New Member
Joined
Apr 4, 2019
Messages
23
Office Version
  1. 365
Platform
  1. Windows
I'm not overly knowledgeable when it comes to VBA so I'm hoping someone can write me a quick VBA for this purpose. I have a long list of items in a tracking file, each line-item has a barcode in column D and a macro button beside each barcode in column E. I need a VBA code so if I click on the macro button in column E, it will print the barcode located to the left in column D.

The challenge is that there are hundreds of barcodes, each with it's own macro so the follow coding I have only works for 1 unless I make a module for each.

Sub PrintSomeCells()
Range ("D360").PrintOut
End Sub

Thank you in advance!
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
What sort of buttons are you using?
ActiveX or Forms Control?
 
Upvote 0
In that case try assigning this to each button
Code:
Sub nathanthomson11()
   Dim Shp As Shape
   
   Set Shp = ActiveSheet.Shapes(Application.Caller)
   Shp.TopLeftCell.Offset(, -1).PrintOut
End Sub
You will need to make sure that the top left corner of each button is in col E
 
Upvote 0
This worked great - thank you! Is there any way to add to this VBA to automatically change the printer to "ZDesigner GX420t" ??

In that case try assigning this to each button
Code:
Sub nathanthomson11()
   Dim Shp As Shape
   
   Set Shp = ActiveSheet.Shapes(Application.Caller)
   Shp.TopLeftCell.Offset(, -1).PrintOut
End Sub
You will need to make sure that the top left corner of each button is in col E
 
Upvote 0
Change A1 to an unused cell & run this
Code:
Sub Chk()
Range("A1").Value = ActivePrinter
End Sub
What does it output?
 
Upvote 0
In that case try
Code:
Sub nathanthomson11()
   Dim Shp As Shape
   Dim Prntr As String
   
   Prntr = ActivePrinter
   ActivePrinter = "ZDesigner GX420t on Ne00:"
   Set Shp = ActiveSheet.Shapes(Application.Caller)
   Shp.TopLeftCell.Offset(, -1).PrintOut
   ActivePrinter = Prntr
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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