philldavis11
New Member
- Joined
- Feb 7, 2022
- Messages
- 3
- Office Version
- 365
- Platform
- Windows
Ok I do not use VBA pretty much ever, but was asked to add an "archive" feature into my workbook. Below is the code that I found online, it works, but it also brings over formulas and I am not too sure what I need to do to adjust it.
So in column "z" I have a "True" or "False" condition formula. In a perfect world, I want rows where "True" in column Z to be sent to the Archive sheet when I hit a button. In my live work version of the sheet, I have formulas throughout, and want to avoid any "#N/A" and want all the values that were present in that row only to appear in my archive sheet. Can someone help me out?
I scrubbed the excel sheet
So in column "z" I have a "True" or "False" condition formula. In a perfect world, I want rows where "True" in column Z to be sent to the Archive sheet when I hit a button. In my live work version of the sheet, I have formulas throughout, and want to avoid any "#N/A" and want all the values that were present in that row only to appear in my archive sheet. Can someone help me out?
I scrubbed the excel sheet
VBA Code:
[FONT=Calibri]Private Sub CommandButton1_Click()
Dim xCell As Range
Dim I As Long
Dim J As Long
Dim K As Long
I = Worksheets("Main").UsedRange.Rows.Count
J = Worksheets("Archive").UsedRange.Rows.Count
If J = 1 Then
If Application.WorksheetFunction.CountA(Worksheets("Archive").UsedRange) = 0 Then J = 0
End If
Set xRg = Worksheets("Main").Range("Z1:Z" & I)
On Error Resume Next
Application.ScreenUpdating = False
For K = 1 To xRg.Count
If CStr(xRg(K).Value) = "True" Then
xRg(K).EntireRow.Copy Destination:=Worksheets("Archive").Range("A" & J + 1)
xRg(K).EntireRow.Delete
If CStr(xRg(K).Value) = "Done" Then
K = K - 1
End If
J = J + 1
End If
Next
Application.ScreenUpdating = True
End Sub[/FONT]