KlausW
Active Member
- Joined
- Sep 9, 2020
- Messages
- 386
- Office Version
- 2016
- Platform
- Windows
I use this VBA code to create sheets based on what is written in column A, starting in A3. What I would like Excel to do is just create folders based on whether there is something in cells A3 and below. As you can see in the example, there are numbers from 1 to 6 but it can easily be 1 to 10 or higher.
All help will be appreciated, regards Klaus W
All help will be appreciated, regards Klaus W
VBA Code:
Option Explicit
Dim wb As Workbook
Dim ws As Worksheet, wsStamdata As Worksheet, wsCopy As Worksheet
Dim Area As Range, Arr() As Variant
Dim Count As Integer
Sub CopyArk()
With Application
.ScreenUpdating = False
.DisplayAlerts = False
End With
Set wb = ThisWorkbook
Set wsCopy = Sheets("Master") ' Navnet på kopisiden
Set wsStamdata = Sheets("Stamdata")
Set Area = wsStamdata.Range("A3")
Set Area = Range(Area, Area.End(xlDown))
Arr = Area
For Count = LBound(Arr, 1) To UBound(Arr, 1)
For Each ws In wb.Sheets
If ws.Name = Arr(Count, 1) Then ws.Delete
Next
Next
For Count = LBound(Arr, 1) To UBound(Arr, 1)
wsCopy.Copy After:=Sheets(Sheets.Count)
Set ws = ActiveSheet
With ws
.Name = Arr(Count, 1)
.Range("A1").Formula = "='Stamdata'!A" & Count + 2
End With
Next
With Application
.ScreenUpdating = True
.DisplayAlerts = True
End With
End Sub
Attachments
Last edited by a moderator: