Hello Everyone !
I need a little help, The code i have now working and i understand how is working, but i wish something smarter.
btw: i have got the sharepoint part to work with this code also, but showing localy for now.
The problem is my main sheet need to be added to sharepoint, so can´t use vba any more that way i need it.
So i have made a sheet for my coworks, so the idea is i want real excel data from main sheet to be showing or copied over to the coworkers sheet, so they only see what they need to see.
rules:
1. i never know what my sheet will be named, cause is diffrent stuff all the time, but the row i need copy is all time the same.
2. the 4 sheet their must not be copied has all time the same name.
Idea:
I need something, their can copy all exist sheet with range from "Main.xlsx", but 4 sheet may not be copied and then everything get insert into the closed coworker sheet.
the idea is the code need to be running when im running my excel sheet, mabye with a timer i copy and saving into coworker every 1min or in real time.
i hope you understand my english since im danish and my grammar is not the best.
I need a little help, The code i have now working and i understand how is working, but i wish something smarter.
btw: i have got the sharepoint part to work with this code also, but showing localy for now.
The problem is my main sheet need to be added to sharepoint, so can´t use vba any more that way i need it.
So i have made a sheet for my coworks, so the idea is i want real excel data from main sheet to be showing or copied over to the coworkers sheet, so they only see what they need to see.
rules:
1. i never know what my sheet will be named, cause is diffrent stuff all the time, but the row i need copy is all time the same.
2. the 4 sheet their must not be copied has all time the same name.
Idea:
I need something, their can copy all exist sheet with range from "Main.xlsx", but 4 sheet may not be copied and then everything get insert into the closed coworker sheet.
the idea is the code need to be running when im running my excel sheet, mabye with a timer i copy and saving into coworker every 1min or in real time.
i hope you understand my english since im danish and my grammar is not the best.
VBA Code:
Sub test()
Dim MainBoook As Workbook
Dim CopyBook As Workbook
Dim ws As Worksheet
Dim SheetName As String
Dim SheetExists As Boolean
Set Mains = Workbooks.Open("C:\Users\demo\Documents\main.xlsm")
Set Copys = Workbooks.Open("C:\Users\demo\Documents\copy.xlsm")
SheetName = InputBox("Writte the name of the sheet")
SheetExists = False
With Copys
'Check if the Sheet exists
For Each ws In .Worksheets
If ws.Name = SheetName Then
SheetExists = True
End If
Next
If SheetExists = False Then
'If the sheet dont exists, create
.Sheets.Add(After:=.Sheets(.Sheets.Count)).Name = SheetName
End If
End With
With Mains
'Check if the Sheet exists
For Each ws In .Worksheets
If ws.Name = SheetName Then
SheetExists = True
Mains.Sheets(SheetName).Range("A1:v1").Copy
Copys.Sheets(SheetName).Range("A1").PasteSpecial Paste:=xlPasteColumnWidths
Copys.Sheets(SheetName).Range("A1").PasteSpecial Paste:=xlPasteAllExceptBorders
Copys.Sheets(SheetName).Range("A1").PasteSpecial Paste:=xlPasteAllUsingSourceTheme
Copys.Sheets(SheetName).Range("A1").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
Mains.Sheets(SheetName).Range("a111:v130").Copy
Copys.Sheets(SheetName).Range("a2").PasteSpecial Paste:=xlPasteColumnWidths
Copys.Sheets(SheetName).Range("a2").PasteSpecial Paste:=xlPasteAllExceptBorders
Copys.Sheets(SheetName).Range("a2").PasteSpecial Paste:=xlPasteAllUsingSourceTheme
Copys.Sheets(SheetName).Range("a2").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
Copys.Close SaveChanges:=True
End If
Next
End With
End Sub