Results 1 to 5 of 5

VBA Code for autoincrement after printing

Threaded View

  1. #1
    Registered User
    Join Date
    09-27-2023
    Location
    Leiden
    MS-Off Ver
    Office 365 Version 2401
    Posts
    7

    VBA Code for autoincrement after printing

    Hello,

    I am working on a batch sheet for our lab. We use batch codes to give every recipe a unique code. We want a sheet that can be filled in by hand, so the batch codes need to be above the table, but changing this every time before printing will be an incredible inconvenience. I tried finding a solution online, but the code didn't work. I want to increase the value of b1, b11, b21 after printing by 3. These values are located in sheet4. I used the following code:

    Private Sub Workbook_BeforePrint(Cancel As Boolean)
    Dim i As Long
    Cancel = True
    Application.EnableEvents = False
    Application.Dialogs(xlDialogPrinterSetup).Show
    With Sheets("Blad4 (Batch)")
        For i = 1 To .Range("B11").Value
        For y = 1 To .Range("B21").Value
            .Range("B1").Value = .Range("B1").Value + 3
            .PrintOut
        Next i
        Next y
    End With
    Application.EnableEvents = True
    End Sub
    If someone has a suggestion to fix this, that would be amazing.

    I really appreciate any help you can provide.
    Test.xlsx
    Last edited by Aanhaai; 02-15-2024 at 03:16 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Data Validation Excel with Offset and Autoincrement
    By iincitr in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-22-2020, 08:12 AM
  2. [SOLVED] Creating String with number autoincrement custom list
    By jaryszek in forum Excel General
    Replies: 4
    Last Post: 01-28-2019, 08:56 AM
  3. [SOLVED] modify vba to autoincrement hours
    By jrtaylor in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-26-2017, 10:37 AM
  4. [SOLVED] How to stop autoincrement in formula
    By cinu97 in forum Excel General
    Replies: 3
    Last Post: 05-19-2015, 10:44 PM
  5. Autoincrement Vlookup While copying down a column
    By Unimog1 in forum Excel General
    Replies: 1
    Last Post: 01-19-2015, 03:44 PM
  6. Autoincrement a single cell on a template
    By maddmikk in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-18-2013, 06:37 PM
  7. [SOLVED] if there is data in B12* autoincrement A12 number
    By zit1343 in forum Excel General
    Replies: 3
    Last Post: 04-09-2012, 12:00 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1