Hi,
I've done my first programming in VBA in Excel and it worked. The program copies a datefile everyday into a masterfile. Now, because I'm lazy I thought I could use the code and transform it a little for the previous years. Instead of using the today command. I would the user to select a year with a Inputbox and then cycle through that year and copy all the information in to the masterfile. With the same code from 'Open the files. Could somebody give me a help forward with this...
Best regards,
Swedish novice Roger
'Skrivet av Roger Håkanson
'
' Join today´s date with ".xls"
' Format the filnamn to match visitor files syntax
Dim filnamn As String
filnamn = Format(Now() - 1, "yymmdd") & ".xls"
'Open the files
ChDir "C:\Passage\Bosse"
Workbooks.Open "c:\passage\Bosse\Summering2006.xls"
ChDir "C:\Passage"
Workbooks.Open (filnamn)
' Copy the information for entrance
Windows(filnamn).Activate
Range("B2:B16").Select
Selection.Copy
' Paste the information for entrance
Windows("Summering2006.xls").Activate
Sheets("Huvudentre").Select
Columns("A:A").Find(What:=Date - 1, LookIn:=xlValues).Activate
ActiveCell.Offset(0, 2).Activate
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone, SkipBlanks:=False_, Transpose:=True
' Copy the information for gallery 1
Windows(filnamn).Activate
Range("D2
16").Select
Selection.Copy
' Paste the information for gallery 1
Windows("Summering2006.xls").Activate
Sheets("Plan1").Select
Columns("A:A").Find(What:=Date - 1, LookIn:=xlValues).Activate
ActiveCell.Offset(0, 2).Activate
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone, SkipBlanks:=False_, Transpose:=True
' Copy the information for gallery 3
Windows(filnamn).Activate
Range("E2:E16").Select
Selection.Copy
' Paste the information for gallery 3
Windows("Summering2006.xls").Activate
Sheets("Plan3").Select
Columns("A:A").Find(What:=Date - 1, LookIn:=xlValues).Activate
ActiveCell.Offset(0, 2).Activate
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone, SkipBlanks:=False_, Transpose:=True
' Copy the information for gallery 4
Windows(filnamn).Activate
Range("F2:F16").Select
Selection.Copy
' Paste the information for gallery 4
Windows("Summering2006.xls").Activate
Sheets("Plan4").Select
Columns("A:A").Find(What:=Date - 1, LookIn:=xlValues).Activate
ActiveCell.Offset(0, 2).Activate
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone, SkipBlanks:=False_, Transpose:=True
' Close the files
Windows(filnamn).Close
Windows("Summering2006.xls").Close savechanges:=True
'Application.Quit
Exit Sub
Errorhandler:
Select Case Err.Number
Case 1005
MsgBox ("There's no file with that date!")
Case Else
MsgBox (Err.Description)
End Select
End Sub
I've done my first programming in VBA in Excel and it worked. The program copies a datefile everyday into a masterfile. Now, because I'm lazy I thought I could use the code and transform it a little for the previous years. Instead of using the today command. I would the user to select a year with a Inputbox and then cycle through that year and copy all the information in to the masterfile. With the same code from 'Open the files. Could somebody give me a help forward with this...
Best regards,
Swedish novice Roger
'Skrivet av Roger Håkanson
'
' Join today´s date with ".xls"
' Format the filnamn to match visitor files syntax
Dim filnamn As String
filnamn = Format(Now() - 1, "yymmdd") & ".xls"
'Open the files
ChDir "C:\Passage\Bosse"
Workbooks.Open "c:\passage\Bosse\Summering2006.xls"
ChDir "C:\Passage"
Workbooks.Open (filnamn)
' Copy the information for entrance
Windows(filnamn).Activate
Range("B2:B16").Select
Selection.Copy
' Paste the information for entrance
Windows("Summering2006.xls").Activate
Sheets("Huvudentre").Select
Columns("A:A").Find(What:=Date - 1, LookIn:=xlValues).Activate
ActiveCell.Offset(0, 2).Activate
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone, SkipBlanks:=False_, Transpose:=True
' Copy the information for gallery 1
Windows(filnamn).Activate
Range("D2
Selection.Copy
' Paste the information for gallery 1
Windows("Summering2006.xls").Activate
Sheets("Plan1").Select
Columns("A:A").Find(What:=Date - 1, LookIn:=xlValues).Activate
ActiveCell.Offset(0, 2).Activate
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone, SkipBlanks:=False_, Transpose:=True
' Copy the information for gallery 3
Windows(filnamn).Activate
Range("E2:E16").Select
Selection.Copy
' Paste the information for gallery 3
Windows("Summering2006.xls").Activate
Sheets("Plan3").Select
Columns("A:A").Find(What:=Date - 1, LookIn:=xlValues).Activate
ActiveCell.Offset(0, 2).Activate
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone, SkipBlanks:=False_, Transpose:=True
' Copy the information for gallery 4
Windows(filnamn).Activate
Range("F2:F16").Select
Selection.Copy
' Paste the information for gallery 4
Windows("Summering2006.xls").Activate
Sheets("Plan4").Select
Columns("A:A").Find(What:=Date - 1, LookIn:=xlValues).Activate
ActiveCell.Offset(0, 2).Activate
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone, SkipBlanks:=False_, Transpose:=True
' Close the files
Windows(filnamn).Close
Windows("Summering2006.xls").Close savechanges:=True
'Application.Quit
Exit Sub
Errorhandler:
Select Case Err.Number
Case 1005
MsgBox ("There's no file with that date!")
Case Else
MsgBox (Err.Description)
End Select
End Sub