Gundisalvus
New Member
- Joined
- Jan 27, 2023
- Messages
- 4
- Office Version
- 365
- Platform
- Windows
Hello all, I am pretty new at VBA and I have been given what I find to be a challenge.
I have to find a #N/A value within a column and when I find that value I have to copy the first 2 values of the row (ex: F85 - #N/A then copy A85, B85) and then paste it onto a diferent sheet onto a list and paste on the first blank cell.
the code I have is
but I think I'm not even close.
I need that he copy and pastes the values for each #N/A values, being those values formula errors and not strings.
Thank you for all the help
I have to find a #N/A value within a column and when I find that value I have to copy the first 2 values of the row (ex: F85 - #N/A then copy A85, B85) and then paste it onto a diferent sheet onto a list and paste on the first blank cell.
the code I have is
VBA Code:
Sub NAFilter()
'Declare variables
Dim DataRg As Range
Dim A As Long
Dim B As Long
'Set variables
A = Worksheets("JE Royalty detail").UsedRange.Rows.Count
C = Worksheets("DB").UsedRange.Rows.Count
'Start from A1
If Application.WorksheetFunction.CountA(Worksheets("DB").UsedRange) = 0 Then C = 0
'Set range for Sheet1
Set DataRg = Worksheets("JE Royalty detail").Range("F3:F93" & A)
On Error Resume Next
Application.ScreenUpdating = False
'For loop
For B = 1 To DataRg.Count
'Value to be searched
If CStr(DataRg(B).Value) = "#N/A" Then
'Copy cells
DataRg(B).Copy Destination:=Worksheets("DB").Range("K" & C + 1)
C = C + 1
End If
Next
Application.ScreenUpdating = True
End Sub
but I think I'm not even close.
I need that he copy and pastes the values for each #N/A values, being those values formula errors and not strings.
Thank you for all the help