I have a report that is sorted by column C. I need to save individual workbooks based off of each item from column C. There are headers in row 1.
Below is the code that I believe should work but isn't. I am also unsure how to site the specifc folder to save it to.
If Target.Address = "$C$2" Then
fname = Range("C2")
ActiveWorkbook.SaveAs Filename:=fname
End If
Here's a macro which will handle targeting cells in a sheet. It must be placed into this specific sheet's code. Example of fname value which is stored in C2 cell is: C:\\Users\\Taisho\\Desktop\\example.xlsx The reason why your macro was not working is probably not assigning variable type to Target
.
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim fname As String
If Target.Address = "$C$2" Then
fname = Range("C2").value2
ActiveWorkbook.SaveAs Filename:=fname
End If
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.