Good day,
I'm currently completing a project for work and I could use some help. I use Excel 2003. I have a few things I want my spreadsheet to do. I have acheived one of these goals but there are others that I have not.
I want my spreadsheet (dubbed wb1) to do the following via a command button:
1. Check if a file exists (dubbed wb2) in a specific directory. If it does not exist, it will create the file and open the file. If it does exist the file will simply open. [achieved]
2. then, the command button will copy the contents of 6 differnt cells that are not in the same row and paste them in the new workbook (wb2) in a single row.
3. at the same time the button will find the next available row in wb2 to paste the contents of the 6 selected cells.
I hope this explanation was good enough. I have reviewd many sources before finally deciding to post my question. I am fairly new to VB so I hope you all can help me.
Thank you
This is what I have so far:
I'm currently completing a project for work and I could use some help. I use Excel 2003. I have a few things I want my spreadsheet to do. I have acheived one of these goals but there are others that I have not.
I want my spreadsheet (dubbed wb1) to do the following via a command button:
1. Check if a file exists (dubbed wb2) in a specific directory. If it does not exist, it will create the file and open the file. If it does exist the file will simply open. [achieved]
2. then, the command button will copy the contents of 6 differnt cells that are not in the same row and paste them in the new workbook (wb2) in a single row.
3. at the same time the button will find the next available row in wb2 to paste the contents of the 6 selected cells.
I hope this explanation was good enough. I have reviewd many sources before finally deciding to post my question. I am fairly new to VB so I hope you all can help me.
Thank you
This is what I have so far:
Code:
Private Sub CommandButton1_Click()
If Dir("h:\My Documents\Calls " & Format(Date, "yyyy-mm-dd") & ".xls") <> "" Then
Set wb1 = ActiveWorkbook.ActiveSheet
Workbooks.Open ("h:\My Documents\Calls " & Format(Date, "yyyy-mm-dd") & ".xls")
Set wb2 = Workbooks("Calls " & Format(Date, "yyyy-mm-dd") & ".xls").Sheets(1)
wb1.Cells(6, 3).Copy wb2.Cells(2, 2)
Workbooks("Calls " & Format(Date, "yyyy-mm-dd") & ".xls").Save
MsgBox "File Existed. It was updated and saved."
Else
Workbooks.Add.SaveAs Filename:="h:\My Documents\Calls " & Format(Date, "yyyy-mm-dd") & ".xls"
Workbooks.Open ("h:\My Documents\Calls " & Format(Date, "yyyy-mm-dd") & ".xls")
Set wb1 = Workbooks("Book1.xls").Sheets("Main Page")
Set wb2 = Workbooks("Calls " & Format(Date, "yyyy-mm-dd") & ".xls").Sheets(1)
wb1.Cells(6, 3).Copy wb2.Cells(2, 2)
Workbooks("Calls " & Format(Date, "yyyy-mm-dd") & ".xls").Save
MsgBox "File didn't exist. It was created, updated and saved."
End If
End Sub