transfers the data, but not from all sheets.

KlausW

Active Member
Joined
Sep 9, 2020
Messages
394
Office Version
  1. 2016
Platform
  1. Windows
Hi all Excel helper
I use the VBA code I got from a good helper here on MrExcel. It transfers the data from all the sheets, to the sheet "Bestilling" . It works really well.
Now I would like to insert a sheet before or after the sheet "Bestilling" that the VBA-code, does not transfer the data from.
All help will be appreciated
Best regards Klaus W

VBA Code:
Sub Rektangelafrundedehjørner4_Klik()

    Dim ws As Worksheet, wsConsol As Worksheet
    Dim lngLastRow As Long, lngPasteRow As Long
   
    Application.ScreenUpdating = False
   
    Set wsConsol = ThisWorkbook.Sheets("Bestilling")
    lngPasteRow = 9 'Starting Row number for the consolidation of the sheet data in 'wsConsol'.
   
    For Each ws In ThisWorkbook.Sheets
        If ws.Name <> wsConsol.Name Then
            On Error Resume Next
                lngLastRow = ws.Range("A:I").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
            On Error GoTo 0
            If lngLastRow >= 2 Then
                ws.Range("A2:I" & lngLastRow).Copy Destination:=wsConsol.Range("K" & lngPasteRow)
                lngPasteRow = wsConsol.Range("K:S").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
            End If
        End If
    Next ws
          
            Range("K9:K15000").NumberFormat = "General"
            Range("K9:K15000").Value = Range("K9:K15000").Value
      
    Application.ScreenUpdating = True
    
    Sheets("Bestilling").Select
    Macro1

End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
You can add the sheet name like
VBA Code:
If ws.Name <> wsConsol.Name And ws.Name <> "Sheet1" Then
 
Upvote 0
Solution
You can add the sheet name like
VBA Code:
If ws.Name <> wsConsol.Name And ws.Name <> "Sheet1" Then
Hi Fluff,
I dont understand that. Where should I put it in the vba code. KW
 
Upvote 0
In place of this line
VBA Code:
If ws.Name <> wsConsol.Name Then
 
Upvote 0
Did you change the "Sheet1" to match the name of the sheet?
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,720
Messages
6,126,436
Members
449,314
Latest member
MrSabo83

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