0

I'm creating a spreadsheet for Excel that has a table, from which, the rows on the selected cells, can be copied to a matrix sheet giving information to a PrintPage sheet, that will be printed out automatically when the macro is called.

The Excel workbook contains the following 4 sheets:

Sheet1: containing a table with a range of information and a lot of VLookup formulas giving information from the "data" sheet

datamatrix: a sheet where data is copied to range ("1:1")

data: a sheet for VLookup formulas in the table on Sheet1

PrintPage: a sheet with a lot of simple "=" formulas, that inherits the information from the datamatrix sheet

I wrote some VBA that loops through my selected information in the table, then, one by one, copies the row of data to the datamatrix sheet, then automatically prints the PrintPage sheet:

Sub Print()

    If Intersect(ActiveCell, ActiveSheet.ListObjects("Table1").DataBodyRange) Is Nothing Then
    
    Else
    
        Dim X As String
        Dim Y As Integer
        Dim Z As Integer
        
        Y = Selection.Rows.Count
        Z = Y
        
        Do While Z > 0
        
            With Rows(ActiveCell.Row)
                .Copy Sheets("datamatrix").Range("1:1")
            End With
            
            Sheets("datamatrix").Range("1:1").Value = ActiveCell.Row
            
        Y = Y + 1
        Z = Z - 1
        
        Sheets("PrintPage").PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
        
        ActiveCell.Offset(1, 0).Select
        
        Loop
                 
    End If

End Sub

My issue is, that when copying data this way, the VLookup formulas in my table breaks, so I need it to be able to paste the data to datamatrix range 1:1, but as text - I just don't know how...

The VBA script does exactly what it is supposed to do, except the pasted values to Sheets("datamatrix").Range("1:1") needs to be pasted as text / values. The way it pastes the data into the datamatrix now, it copies the formulas that will lose it's references.

BigBen
  • 46,229
  • 7
  • 24
  • 40

0 Answers0