I am still a newbie trying to fly when I can hardly even crawl yet.
This code on it's own works fine to populate Master SHEET Columns D,E,F,G based on what is pasted into Master SHEET Column B.
Ref: CODE A
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim RNG As Range
Application.EnableEvents = False
On Error Resume Next
Set RNG = Range("B:B").SpecialCells(xlConstants)
If Not RNG Is Nothing Then
RNG.Offset(1, 2).FormulaR1C1 = "=""Deny from "" & RC[-2]"
RNG.Offset(1, 3).FormulaR1C1 = "=""Allow from "" & RC[-3]"
RNG.Offset(1, 4).FormulaR1C1 = "=""/sbin/iptables -A INPUT -p udp -s "" & RC[-4]& "" -j DROP"""
RNG.Offset(1, 5).FormulaR1C1 = "=""/sbin/iptables -A INPUT -p tcp -s "" & RC[-5]& "" -j DROP"""
Else
ActiveSheet.UsedRange.Offset(1).Clear
End If
Application.EnableEvents = True
End Sub
This code on it's own partially works in that a selection from the drop list will get data just not the correct data, it gets all data.
Ref: CODE B
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim LR As Long
LR = Sheets("Data").Cells.Find("*", Cells(Rows.Count, Columns.Count), SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Row
Application.ScreenUpdating = False
Application.EnableEvents = False
Sheets("Master").UsedRange.Offset(2, 0).ClearContents
With Sheets("Data")
.AutoFilterMode = False
.Range("A2:AA" & LR).AutoFilter Field:=1, Criteria1:= _
Sheets("Master").Range("A1").Value
.UsedRange.Offset(1, 0).SpecialCells(xlVisible).Copy
Sheets("Master").Range("B2").PasteSpecial
.AutoFilterMode = False
End With
Application.CutCopyMode = False
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
What should it do?
The drop list should have a blank line when selected this clears the sheet below Row 1 so as to preserve headers.
When you select from the drop list the macro should find the column of data related to that selection
and automatically populate Master SHEET Column B (CIDR).
With Master SHEET Column B (CIDR) populated trigger the population of Columns D,E,F,G
Example:
If AF - AFGHANISTAN is selected this should only get Column A from SHEET Data and populate Master SHEET Column B (CIDR).
The now populated Master SHEET Column B (CIDR) should trigger Ref: CODE A which should now populate Master SHEET Columns D,E,F,G
Attached workbook is using Ref: CODE B as a filter function in module 1 manually run for now so as to not interfere with macro in Master SHEET
Bookmarks