[英]Trying to have macro filter everything in a column and save individual workbooks per sorted item in excel vba
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. 我有一个按C列排序的报告。我需要根据C列中的每个项目保存单个工作簿。第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.
我也不确定如何将specifc文件夹保存到该文件夹。
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
. 存储在C2单元格中的fname值示例如下:C:\\ Users \\ Taisho \\ Desktop \\ example.xlsx宏不起作用的原因可能是未将变量类型分配给
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.