I fullfilled all requirements but i would like to have a my result in another excel sheet rather showing the result in the same sheet.
Here is my code:
Dim filterrange As Range
Set filterrange = ThisWorkbook.Sheets("sheet1").Cells(2, ThisWorkbook.Sheets("sheet1").Cells(1, Columns.Count).End(xlToLeft).Column) ' get columns e.g. name, state, etc.
filterrange.AutoFilter Field:=11, Criteria1:=Array("GBR" _
, "MAD", "NCE", "="), Operator:=xlFilterValues
filterrange.AutoFilter Field:=21, Criteria1:="Yes" ' activeconnect
filterrange.AutoFilter Field:=24, Criteria1:="=" ' clustername
filterrange.AutoFilter Field:=6, Criteria1:= _
"<>*@sca.ama.com*", Operator:=xlAnd ' e-mail
filterrange.AutoFilter Field:=10, Criteria1:=Array( _
"Madrid", "Sophia-antipolis"), Operator:=xlFilterValues
For Each cell In filterrange.CurrentRegion.SpecialCells(xlCellTypeVisible).Rows
If Cells(cell.Row, 24) = "" Then
Select Case Cells(cell.Row, 11).Value
Case "NCE"
Cells(cell.Row, 24) = "nceccm.iis.net"
Case "MAD"
Cells(cell.Row, 24) = "mucpccm.iis.net"
End Select
End If
Next cell
Dim ws as worksheet
set ws = worksheets.add("Sheet2") after:=Activesheet
ws.name = "abc"
ws.copy
worksheets("abc").paste
end sub
The result should dipslay in another sheet(sheet2), but for me its showing the result in sheet1 and sheet2, the actual data must remain unchanged in sheet1 when we excute the code the result must be displayed in sheet2. can anyone please help me out.
Sub Example()
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim filterrange As Range
Set ws1 = ThisWorkbook.Sheets("Sheet1")
For Each Worksheet In ThisWorkbook.Worksheets
If Worksheet.Name = "abc" Then
Set ws2 = Worksheet
End If
Next Worksheet
If ws2 Is Nothing Then
Set ws2 = ThisWorkbook.Worksheets.Add(after:=ActiveSheet)
ws2.Name = "abc"
End If
ws1.Activate
Set filterrange = ws1.Cells(2, ws1.Cells(1, Columns.Count).End(xlToLeft).Column) ' get columns e.g. name, state, etc.
filterrange.AutoFilter Field:=11, Criteria1:=Array("GBR" _
, "MAD", "NCE", "="), Operator:=xlFilterValues
filterrange.AutoFilter Field:=21, Criteria1:="Yes" ' activeconnect
filterrange.AutoFilter Field:=24, Criteria1:="=" ' clustername
filterrange.AutoFilter Field:=6, Criteria1:= _
"<>*@sca.amadeus.com*", Operator:=xlAnd ' e-mail
filterrange.AutoFilter Field:=10, Criteria1:=Array( _
"Madrid", "Sophia-antipolis"), Operator:=xlFilterValues
For Each cell In filterrange.CurrentRegion.SpecialCells(xlCellTypeVisible).Rows
If Cells(cell.Row, 24) = "" Then
Select Case Cells(cell.Row, 11).Value
Case "NCE"
Cells(cell.Row, 24) = "nceiptccm.iis.amadeus.net"
Case "MAD"
Cells(cell.Row, 24) = "muciptccm.iis.amadeus.net"
End Select
End If
Next cell
filterrange.SpecialCells(xlCellTypeVisible).Copy
ws2.Activate
ws2.Range("a1").PasteSpecial (xlPasteValues)
ws1.Activate
On Error Resume Next
ws1.ShowAllData
On Error GoTo 0
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.