Autosave Code Problem

excellearnerz

New Member
Joined
May 5, 2020
Messages
17
Office Version
  1. 365
  2. 2016
  3. 2011
  4. 2010
Platform
  1. Windows
Good day,

I scrounged up a code I dont fully understand, but it seems to work. The goal of the code is that when there are any changes in the cell range I defined, the spreadsheet will autosave/export as a pdf file. However, I want that when another set of changes are submitted to the spreadsheet, it will save again with a sequential file name, and not overwrite the old save.

Here is the code:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Step 1: Does the changed range intersect?
If Intersect(Target, Range("A1:AT55")) Is Nothing Then
'Step 2: If there is no intersection, exit procedure
Exit Sub
'Step 3: If there is an intersection, save the workbook
Else
Sheet4.ExportAsFixedFormat xlTypePDF, "C:\Users\Office-PC\Desktop\Destiny\INRToday.pdf"
'Step 4: Close out the If statement
End If
End Sub
File-Copy-icon.png




Any help will be greatly appreciated.
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
yes but there was a range that was set through dim
That does not make it work like the Worksheet_Change event procedure does. In the Worksheet_Change procedure, the Target is the range of cells that were just changed to trigger the code to run. That is inherent to how Worksheet_Change works, the user/programmer does not affect it.

There is no way to make Worksheet_Calculate behave the same way. It simply runs whenever there is re-calculation done anywhere on the sheet. It does not tell you what cell changed.
All that declaring Target with a Dim statement does is create a new range variable like any other user declared range variable. Naming it "Target" will NOT make it work the way "Target" does in a Worksheet_Change event procedure.
 
Upvote 0
@excellearnerz it is never a good idea to name a range with a keyword from excel so creating Target can create even more problems
 
Upvote 0
sir, I am just frankensteining this code, I know little to nothing about coding. pls..
 
Upvote 0

Forum statistics

Threads
1,214,429
Messages
6,119,435
Members
448,898
Latest member
dukenia71

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
Back
Top