Help with macro

gemsy62

New Member
Joined
Feb 21, 2009
Messages
8
Hello,

I current have a macro which saves data from cells to another worksheet in the excel file called results.

Is it possible to save this data to a different workbook? Basically I want to save performance scores each month and don't want the whole company to be able to view these on the template.

Also, is it possible to build a macro that saves the file in a set format. I have a cell which has the name, month & date. Is it possible to have a macro that saves the file as namemonthdate.xls in a set folder?

The macro I have which currently exports the data to the results spreadsheet is

Sub ButtonClick()
Dim historyWks As Worksheet
Dim inputWks As Worksheet
Dim nextRow As Long
Dim oCol As Long
Dim myRng As Range
Dim myCopy As String
Dim myCell As Range

'cells to copy from Input sheet - some contain formulas
myCopy = "X6,I6,B6,S6,N2,T2,AH10,AH14,AH18,AH22,AH28"
Set inputWks = Worksheets("Input")
Set historyWks = Worksheets("Results")
With historyWks
nextRow = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0).Row
End With
With inputWks
Set myRng = .Range(myCopy)
If Application.CountA(myRng) <> myRng.Cells.Count Then
MsgBox "Please complete all the boxes. If not applicable, enter N/A"
Exit Sub
End If
End With
With historyWks
With .Cells(nextRow, "A")
.Value = Now
.NumberFormat = "mm/dd/yyyy hh:mm:ss"
End With
.Cells(nextRow, "B").Value = Application.UserName
oCol = 3
For Each myCell In myRng.Cells
historyWks.Cells(nextRow, oCol).Value = myCell.Value
oCol = oCol + 1
Next myCell
End With

'clear input cells that contain constants
With inputWks
On Error Resume Next
With .Range(myCopy).Cells.SpecialCells(xlCellTypeConstants)
.ClearContents
Application.Goto .Cells(1) ', Scroll:=True
End With
On Error GoTo 0
End With
End Sub

Thanks,

Gemma
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

gemsy62

New Member
Joined
Feb 21, 2009
Messages
8
Just to update...

Have managed to write a macro which saves the file to the desktop using a cell which specifies the file name.

I just can't work out how to get the data to copy to a seperate workbook. This is a file that would not be open, so the data would need to write to the workbook, save and close the file.
 
Upvote 0

Forum statistics

Threads
1,195,633
Messages
6,010,818
Members
441,569
Latest member
PeggyLee

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
Top