Check more Sheets but keep format

pantakos

Board Regular
Joined
Oct 10, 2012
Messages
158
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Can you please help me.

If I want to check another column at the same sheet (and all other sheets in the array) what can I do?

I tried to change sht = Array("E") to sht = Array("E", "K") in order to check both Columns and add it where the code paste the values, but no luck.

I need to keep the table.

What can I do?



Thank you in advance,

Gerasimos



SAMPLE5.xlsm



PS: Question have been posted here https://www.excelforum.com/exc…-problem.html#post5658628 and Check more Sheets but keep format - OzGrid Free Excel/VBA Help Forum
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
See if this does what you want:
VBA Code:
Sub BuiltIT()
    Application.ScreenUpdating = False
    Dim ws As Worksheet, desWS As Worksheet, rng As Range, lRow As Long
    Set desWS = Sheets("PROFORMA")
    With desWS
        .ListObjects("Table5").DataBodyRange.Delete
        .Range("E15").Formula = "=C15*D15"
        .Rows(16 & ":" & Sheets("PROFORMA").Rows.Count).Delete
    End With
    For Each ws In Sheets(Array("AUDIO", "AUDIO2"))
        With ws
            For Each rng In .Range("E2", .Range("E" & .Rows.Count).End(xlUp))
                If rng <> "" Then
                    With desWS
                        .Cells(.Rows.Count, "B").End(xlUp).Offset(1).Resize(, 3).Value = Array(rng.Offset(, -3), rng.Offset(, -1), rng)
                    End With
                End If
            Next rng
            For Each rng In .Range("K2", .Range("K" & .Rows.Count).End(xlUp))
                If rng <> "" Then
                    With desWS
                        .Cells(.Rows.Count, "B").End(xlUp).Offset(1).Resize(, 3).Value = Array(rng.Offset(, -3), rng.Offset(, -1), rng)
                    End With
                End If
            Next rng
        End With
    Next ws
    desWS.Rows(15).Delete
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
@mumps Yes that do the job, but by mistake I uploaded the wrong sample.

Here is the correct one, using tables.
As you can see I need to place sheet name, when the insert occurs etc.


Sample10

Thank you for your effort
 
Upvote 0
Try:
VBA Code:
Sub BuiltIT()
    Application.ScreenUpdating = False
    Dim ws As Worksheet, desWS As Worksheet, rng As Range, lRow As Long
    Set desWS = Sheets("PROFORMA")
    With desWS
        .ListObjects("Table5").DataBodyRange.Delete
        .Range("E15").Formula = "=C15*D15"
        .Rows(16 & ":" & Sheets("PROFORMA").Rows.Count).Delete
    End With
    For Each ws In Sheets
        If ws.Name <> "PROFORMA" Then
            With ws
                For Each rng In .Range("E13", .Range("E" & .Rows.Count).End(xlUp))
                    If rng <> "" Then
                        With desWS
                            .Cells(.Rows.Count, "B").End(xlUp).Offset(1).Resize(, 3).Value = Array(rng.Offset(, -3), rng.Offset(, -1), rng)
                        End With
                    End If
                Next rng
                For Each rng In .Range("K13", .Range("K" & .Rows.Count).End(xlUp))
                    If rng <> "" Then
                        With desWS
                            .Cells(.Rows.Count, "B").End(xlUp).Offset(1).Resize(, 3).Value = Array(rng.Offset(, -3), rng.Offset(, -1), rng)
                        End With
                    End If
                Next rng
            End With
        End If
    Next ws
    desWS.Rows(15).Delete
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Unfortenetly it doest work proper. Thank you for your time and effort.

The basic idea is the check all column E and K , and check if there is a numeric value and only, If yes then Copy Price per Day (column D or H depends the PCS value where it is) at Proforma Column C ,
then copy E & K to column D of Proforma and copy B & H to column B at proforma.

And copy the sheet name at B at the start of the check at each sheet.

Please take a look at the image I attach to see the result that your script does .

SnapShot.jpg


Thank you
 
Upvote 0
Can this code modified to use two columns ?

VBA Code:
Sub BuildIT()
Dim ws As Variant, sht As Variant
Dim i As Long, lr As Long, nr As Long, c As Long
Dim cell As Range
Application.ScreenUpdating = False
' Set array of worksheet names to copy from
ws = Array("AUDIO", "AUDIO1", "AUDIO2)
' Array of columns to check
sht = Array("E")   <----  AND HERE ADD ALSO "M" COLUMN AND MAKE THE NECCESARY COPIES OF CELLS ETC
nr = 15


'On Error Resume Next
Sheets("PROFORMA").ListObjects("Table5").DataBodyRange.Delete
Sheets("PROFORMA").Range("E15").Formula = "=C15*D15"
Sheets("PROFORMA").Rows(16 & ":" & Sheets("PROFORMA").Rows.Count).Delete

' Loop through all sheets in sheets array
For i = LBound(ws) To UBound(ws)
' Loop through all columns in the column array
For c = LBound(sht) To UBound(sht)
' Find last row in column with data
    With Sheets(ws(i))
        Sheets("PROFORMA").Cells(nr, "B") = Sheets(ws(i)).Name
        Sheets("PROFORMA").Cells(nr, "B").Interior.Color = 65535  ' add Newline
        lr = .Cells(Rows.Count, sht(c)).End(xlUp).Row
        ' Loop through all cells in column
        For Each cell In .Range(.Cells(1, sht(c)), .Cells(lr, sht(c)))
        ' Check to see if value is numeric and not 0
              If (IsNumeric(cell.Value)) And (cell.Value <> 0) Then
                nr = nr + 1
            ' Copy Description
            .Cells(cell.Row, "B").Copy
            Sheets("PROFORMA").Cells(nr, "B").PasteSpecial Paste:=xlPasteValues

            Sheets("PROFORMA").Cells(nr, "B").Interior.Pattern = xlNone
            ' Copy Price
            .Cells(cell.Row, "D").Copy
            Sheets("PROFORMA").Cells(nr, "C").PasteSpecial Paste:=xlPasteValues

            ' Copy Quantity
            .Cells(cell.Row, "H").Copy
            Sheets("PROFORMA").Cells(nr, "D").PasteSpecial Paste:=xlPasteValues


           
            ' Increment nr counter
            End If
        Next cell
    End With
Next c
nr = nr + 1
Next i

Application.ScreenUpdating = True

MsgBox "Done! Invoice created."

End Sub
 
Upvote 0
This is what I got when I tested the macro below:
SAMPLE10.xlsm
BCDE
14DESCRIPTIONPRICEPCSTOTAL
15AUDIO0
16PRODUCT 110.00 €10100
17PRODUCT 310.00 €12120
18AUDIO30
19PRODUCT210100.00 €202000
20PRODUCT211100.00 €303000
21PRODUCT23055.00 €3165
22PRODUCT23555.00 €4220
23AUDIO40
24PRODUCT27255.00 €12660
25PRODUCT27355.00 €241320
PROFORMA


VBA Code:
Sub BuiltIT()
    Application.ScreenUpdating = False
    Dim ws As Worksheet, desWS As Worksheet, rng As Range, lRow As Long
    Set desWS = Sheets("PROFORMA")
    With desWS
        .ListObjects("Table5").DataBodyRange.Delete
        .Range("E15").Formula = "=C15*D15"
        .Rows(16 & ":" & Sheets("PROFORMA").Rows.Count).Delete
    End With
    For Each ws In Sheets
        If ws.Name <> "PROFORMA" Then
            With ws
                If .Range("E" & .Rows.Count).End(xlUp).Row > 12 Or .Range("K" & .Rows.Count).End(xlUp).Row > 12 Then
                    desWS.Cells(desWS.Rows.Count, "B").End(xlUp).Offset(1) = ws.Name
                End If
                If .Range("E" & .Rows.Count).End(xlUp).Row > 12 Then
                    For Each rng In .Range("E13", .Range("E" & .Rows.Count).End(xlUp))
                        If rng <> "" Then
                            With desWS
                                .Cells(.Rows.Count, "B").End(xlUp).Offset(1).Resize(, 3).Value = Array(rng.Offset(, -3), rng.Offset(, -1), rng)
                            End With
                        End If
                    Next rng
                End If
                If .Range("K" & .Rows.Count).End(xlUp).Row > 12 Then
                    For Each rng In .Range("K13", .Range("K" & .Rows.Count).End(xlUp))
                        If rng <> "" Then
                            With desWS
                                .Cells(.Rows.Count, "B").End(xlUp).Offset(1).Resize(, 3).Value = Array(rng.Offset(, -3), rng.Offset(, -1), rng)
                            End With
                        End If
                    Next rng
                End If
            End With
        End If
    Next ws
    desWS.Rows(15).Delete
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
You are correct. Is it checking if it is a number ? and check all column E and K ?
Thank you !
 
Upvote 0
@mumps Oops! Something new!
Sometimes, it gives me this error (mostly of the time)

1.jpg

Here

2.jpg


Why does that?

And a last one, the name of the sheet need to be Yellow the other lines with the products no color.

Thank you again !
 
Upvote 0

Forum statistics

Threads
1,214,905
Messages
6,122,174
Members
449,071
Latest member
cdnMech

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