How to create "Array" that looks at column values?

dpnab

New Member
Joined
Apr 12, 2022
Messages
35
Office Version
  1. 365
Platform
  1. Windows
I currently use the following VBA formula to print out a separate sheet based on each "ABC" value in the "array".

Sub PrintAll()
Dim i As Integer
Dim VList As Variant

VList = Array("ABC123","ABC456","ABC789")

For i = LBound(VList) To UBound(VList)
Range("B1") = VList(i)
ActiveSheet.PrintOut
Next
End Sub

I have a list of items in Sheet "Products" and in Column A starting from A2, I have all these product numbers. Instead of manually entering them into the macro (ABC123, ABC456, ABC789, etc etc), I want it to just use all the values that in in Column A.

This will change on a daily basis, so I'd like it to search in Column A and stop populating when a cell is blank.

What can I add to do this?

Thanks!
 
Ok, how about
VBA Code:
Sub PrintAll()
Dim i As Integer
Dim VList As Variant

With Sheets("main")
   VList = .Range("A2", .Range("A" & Rows.Count).End(xlUp)).Value
End With
If IsArray(VList) Then
   For i = LBound(VList) To UBound(VList)
   Range("B1") = VList(i, 1)
   ActiveSheet.PrintOut
   Next
Else
   Range("B1") = VList
   ActiveSheet.PrintOut
End If
End Sub
 
Upvote 0
Solution

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Ok, how about
VBA Code:
Sub PrintAll()
Dim i As Integer
Dim VList As Variant

With Sheets("main")
   VList = .Range("A2", .Range("A" & Rows.Count).End(xlUp)).Value
End With
If IsArray(VList) Then
   For i = LBound(VList) To UBound(VList)
   Range("B1") = VList(i, 1)
   ActiveSheet.PrintOut
   Next
Else
   Range("B1") = VList
   ActiveSheet.PrintOut
End If
End Sub
That did it, thanks!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,399
Messages
6,119,279
Members
448,884
Latest member
chuffman431a

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