In Excel VBA i have a target column i.e Column M in which i am pasting my formula values based on my source column i.e Column C ( which is my filtering criteria) but i am not getting my formula in my required column instead formula gets pasted in all header as well
Please find the attached excel sheet
Please also find the code which i used to get the data More concern about case "Contain" Based on sheet "Mapping Rules" sheet i am using my formulas to manipulate data in "PMP Report" sheet
What i have observed is when there is only 1 filterd record in PMP_Report sheet it does not paste records in required column properly but when it has 2 or more filtered records then it shows proper output at required cell. Is there anyone who can help me to figure out how to get this done Still new to VBA programming but trying some automation for my work
Also if you want any doubts about this or need any additional information pls ask me
Case "contain"
sh2.Activate
sh2.Cells(1, l).Select
Selection.AutoFilter
sh2.Range("A1:N" & pmplastrow).AutoFilter Field:=sh2.Cells(2, l).Column, Criteria1:="=" & "*" & sh8.Cells(i, 4) & "*", Operator:=xlAnd
For m = 1 To pmplastcol
If InStr(sh8.Cells(i, 5), sh2.Cells(1, m)) <> 0 Then
sh2.Cells(2, m).Select
Set Rng = sh2.Range(Cells(2, m).Address & ":" & Cells(pmplastrow, m).Address).SpecialCells(xlCellTypeVisible) ' target range
Set rng1 = sh2.Range(Cells(2, l).Address & ":" & Cells(pmplastrow, l).Address).SpecialCells(xlCellTypeVisible) ' source range
Select Case sh8.Cells(i, 6)
Case "between"
For k = 2 To pmplastrow
If Intersect(sh2.Cells(k, l), rng1) Is Nothing Then
Else
Rng.SpecialCells(xlCellTypeVisible).FormulaR1C1 = VBA.Trim(VBA.Mid(sh2.Cells(k, l), Excel.WorksheetFunction.Search(sh8.Cells(i, 7), sh2.Cells(k, l)) + VBA.Len(sh8.Cells(i, 7)), Excel.WorksheetFunction.Search(sh8.Cells(i, 8), sh2.Cells(k, l)) - Excel.WorksheetFunction.Search(sh8.Cells(i, 7), sh2.Cells(k, l)) - VBA.Len(sh8.Cells(i, 7))))
End If
Next k
Case "is"
For k = 2 To pmplastrow
If Intersect(sh2.Cells(k, l), rng1) Is Nothing Then
Else
Rng.SpecialCells(xlCellTypeVisible).FormulaR1C1 = VBA.Trim(sh8.Cells(i, 7))
End If
Next k
End Select
sh2.ShowAllData
End If
Next m