Hi Folks
I have been pulling my hair out with this, i have found pieces of code around the place but this is just not working for me. to give you an idea, the code selects all of the data in x cells, copies the data, opens a workbook (master data sheet), finds the first blank cell in column A and pastes the data. Saves that workbook and closes it then selects the data from a2 downwards and deletes it.
Now the sheet that processes this macro is also linked to the master data spreadsheet to refresh the data for viewing purposes only, when i refresh the data in this i start to have issues.
It does all the steps up to save, once i do save it brings do you want to replace the data. even if i select yes it does not save the copied over data..
any help would be appreciated
Here is my code:
Sub Macro2()
'
' Macro2 Macro
'
If MsgBox("Only click Yes if you have finished the form, press No to stop.", vbYesNo) = vbNo Then Exit Sub
On Error GoTo Error
Range("A2").Resize(Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row, _
Cells.Find(What:="*", SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Column).Select
Selection.Copy
Workbooks.Open Filename:="LOCATION-MasterData.xlsx"
Dim ws As Worksheet
Set ws = ActiveSheet
For Each cell In ws.Columns(1).Cells
If Len(cell) = 0 Then cell.Select: Exit For
Next cell
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWorkbook.Save
ActiveWorkbook.Close
Range("A2").Resize(Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row, _
Cells.Find(What:="*", SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Column).Select
Selection.Delete
MsgBox ("Export Successful")
Exit Sub
Error:
MsgBox ("Export not successful, if this continues please contact me")
End Sub
I have been pulling my hair out with this, i have found pieces of code around the place but this is just not working for me. to give you an idea, the code selects all of the data in x cells, copies the data, opens a workbook (master data sheet), finds the first blank cell in column A and pastes the data. Saves that workbook and closes it then selects the data from a2 downwards and deletes it.
Now the sheet that processes this macro is also linked to the master data spreadsheet to refresh the data for viewing purposes only, when i refresh the data in this i start to have issues.
It does all the steps up to save, once i do save it brings do you want to replace the data. even if i select yes it does not save the copied over data..
any help would be appreciated
Here is my code:
Sub Macro2()
'
' Macro2 Macro
'
If MsgBox("Only click Yes if you have finished the form, press No to stop.", vbYesNo) = vbNo Then Exit Sub
On Error GoTo Error
Range("A2").Resize(Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row, _
Cells.Find(What:="*", SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Column).Select
Selection.Copy
Workbooks.Open Filename:="LOCATION-MasterData.xlsx"
Dim ws As Worksheet
Set ws = ActiveSheet
For Each cell In ws.Columns(1).Cells
If Len(cell) = 0 Then cell.Select: Exit For
Next cell
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWorkbook.Save
ActiveWorkbook.Close
Range("A2").Resize(Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row, _
Cells.Find(What:="*", SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Column).Select
Selection.Delete
MsgBox ("Export Successful")
Exit Sub
Error:
MsgBox ("Export not successful, if this continues please contact me")
End Sub