[英]How to set condition in excel vba based on cell value?
我想問一個問題。 我有關於如何在vba中保存excel的最后一行的代碼,但是在我的代碼中,我想添加一個條件,例如,如果E列的cell.value =“ disable”,則將保存選擇的最后一行,然后
像這樣保存WB.SaveAs filename:=“ C:\\ New Folder \\”&filename,FileFormat:= 51
萬一
這是我的密碼
Sub Increment()
' change A1 to the cell you wish to Increment
Range("A1").Value = Range("A1").Value + 1
End Sub
Private Sub CommandButton1_Click()
Call SaveLastLine
End Sub
Sub SaveLastLine()
'Variable declaration
Dim score As String
Dim WB As Workbook, _
filename As String
'Turn off screen updating and alerts
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'Make a copy of the last line of Active Sheet
newName = ActiveSheet.Name
Range("B1").Select
Selection.End(xlDown).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Workbooks.Add
ActiveSheet.Paste
Call Increment
FileNane1 = Range("A1").Value
Set WB = ActiveWorkbook
filename = newName & FileNane1 & ".xlsx"
WB.SaveAs filename:="C:\New Folder\" & filename, FileFormat:=51
'Restore screen updating and alerts
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
是否有人可以幫助我在我的vba代碼中添加一個條件?
請任何人都可以幫助我。
FileName1 = Range("A1").Value
if FileName1 = "disable" then
Set WB = ActiveWorkbook
filename = newName & FileNane1 & ".xlsx"
WB.SaveAs filename:="C:\New Folder\" & filename, FileFormat:=51
end if
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.