Copy/Refence specific cells if particular cell is equal to value

jhemz

New Member
Joined
Dec 19, 2013
Messages
15
Hi Guys,

I would like to ask if my idea is possible and doable. Currently, I have two worksheets (System Network and AttackReport). I want to copy or reference specific cells if the value of cells in Column B in System Network sheet is equal to NetworkAttack.

If ColumnB=NetworkAttack, I want to reference or copy of that row:
- ColumnA in System Network worksheet to ColumnA in AttackReport worksheet
- ColumnC in System Network worksheet to ColumnB in AttackReport worksheet
- ColumnE in System Network worksheet to ColumnF in AttackReport worksheet
- ColumnF in System Network worksheet to ColumnG in AttackReport worksheet
- ColumnG in System Network worksheet to ColumnI in AttackReport worksheet
- ColumnH in System Network worksheet to ColumnJ in AttackReport worksheet
- ColumnI in System Network worksheet to ColumnL in AttackReport worksheet
- ColumnJ in System Network worksheet to ColumnM in AttackReport worksheet

72zr0l.jpg


29o0opt.jpg



Could this be possible?


Thanks in advance!
 

Some videos you may like

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,979
Office Version
  1. 2013
Platform
  1. Windows
Try this. This assumes you want the data entered on the next available row of Attack Report.
Code:
Sub copyData()
Dim sh1 As Worksheet, sh2 As Worksheet, lr As Long, rng As Range, c As Range, rw As Long
Set sh1 = Sheets("System Network")
Set sh2 = Sheets("Attack Report")
lr = sh1.Cells(Rows.Count, 2).End(xlUp).Row
Set rng = sh1.Range("B7:B" & lr)
    For Each c In rng
        If c.Value = "NetworkAttack" Then
            rw = sh2.Cells(Rows.Count, 1).End(xlUp)(2).Row
            With sh2
                .Range("A" & rw) = c.Value
                .Range("B" & rw) = c.Offset(0, 2).Value
                .Range("F" & rw) = c.Offset(0, 4).Value
                .Range("G" & rw) = c.Offset(0, 5).Value
                .Range("I" & rw) = c.Offset(0, 6).Value
                .Range("J" & rw) = c.Offset(0, 7).Value
                .Range("L" & rw) = c.Offset(0, 8).Value
                .Range("M" & rw) = c.Offset(0, 9).Value
            End With
        End If
    Next
End Sub
 

jhemz

New Member
Joined
Dec 19, 2013
Messages
15
Try this. This assumes you want the data entered on the next available row of Attack Report.
Code:
Sub copyData()
Dim sh1 As Worksheet, sh2 As Worksheet, lr As Long, rng As Range, c As Range, rw As Long
Set sh1 = Sheets("System Network")
Set sh2 = Sheets("Attack Report")
lr = sh1.Cells(Rows.Count, 2).End(xlUp).Row
Set rng = sh1.Range("B7:B" & lr)
    For Each c In rng
        If c.Value = "NetworkAttack" Then
            rw = sh2.Cells(Rows.Count, 1).End(xlUp)(2).Row
            With sh2
                .Range("A" & rw) = c.Value
                .Range("B" & rw) = c.Offset(0, 2).Value
                .Range("F" & rw) = c.Offset(0, 4).Value
                .Range("G" & rw) = c.Offset(0, 5).Value
                .Range("I" & rw) = c.Offset(0, 6).Value
                .Range("J" & rw) = c.Offset(0, 7).Value
                .Range("L" & rw) = c.Offset(0, 8).Value
                .Range("M" & rw) = c.Offset(0, 9).Value
            End With
        End If
    Next
End Sub

Hi JLGWhiz,

I just corrected some functions but it does the job very well. Many thanks for the help! :)
 

jhemz

New Member
Joined
Dec 19, 2013
Messages
15
Try this. This assumes you want the data entered on the next available row of Attack Report.
Code:
Sub copyData()
Dim sh1 As Worksheet, sh2 As Worksheet, lr As Long, rng As Range, c As Range, rw As Long
Set sh1 = Sheets("System Network")
Set sh2 = Sheets("Attack Report")
lr = sh1.Cells(Rows.Count, 2).End(xlUp).Row
Set rng = sh1.Range("B7:B" & lr)
    For Each c In rng
        If c.Value = "NetworkAttack" Then
            rw = sh2.Cells(Rows.Count, 1).End(xlUp)(2).Row
            With sh2
                .Range("A" & rw) = c.Value
                .Range("B" & rw) = c.Offset(0, 2).Value
                .Range("F" & rw) = c.Offset(0, 4).Value
                .Range("G" & rw) = c.Offset(0, 5).Value
                .Range("I" & rw) = c.Offset(0, 6).Value
                .Range("J" & rw) = c.Offset(0, 7).Value
                .Range("L" & rw) = c.Offset(0, 8).Value
                .Range("M" & rw) = c.Offset(0, 9).Value
            End With
        End If
    Next
End Sub

Hi JLGWhiz,

Everytime the macro runs, it still copy the previously copied cell so it ended with duplicate rows. Is there a way to skip the rows which was already previously copied/transferred?
 

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,979
Office Version
  1. 2013
Platform
  1. Windows

ADVERTISEMENT

Please post the code with the changes you made.
 

jhemz

New Member
Joined
Dec 19, 2013
Messages
15
Hi JLGWhiz,

I didn't make changes on the on the code, but on the header arrangement (row 6) for the AttackReport sheet.
 

jhemz

New Member
Joined
Dec 19, 2013
Messages
15
Hi JLGWhiz,

Here is the code I modified quite a bit:

Sub copyData()
Dim sh1 As Worksheet, sh2 As Worksheet, lr As Long, rng As Range, c As Range, rw As Long
Set sh1 = Sheets("System Network")
Set sh2 = Sheets("Attack Report")
lr = sh1.Cells(Rows.Count, 2).End(xlUp).Row
Set rng = sh1.Range("B7:B" & lr)
For Each c In rng
If c.Value = "NetworkAttack" Then
rw = sh2.Cells(Rows.Count, 1).End(xlUp)(2).Row
With sh2
.Range("A" & rw) = c.Offset(0, -1).Value
.Range("B" & rw) = c.Offset(0, 1).Value
.Range("F" & rw) = c.Offset(0, 3).Value
.Range("G" & rw) = c.Offset(0, 4).Value
.Range("I" & rw) = c.Offset(0, 5).Value
.Range("J" & rw) = c.Offset(0, 6).Value
.Range("L" & rw) = c.Offset(0, 7).Value
.Range("M" & rw) = c.Offset(0, 8).Value
End With
End If
Next
End Sub


How can the macro run every 1 minute or so? Also, is there a way that whenever the macro runs, it skips the previously referenced/copied cell?


Thanks!
 

Watch MrExcel Video

Forum statistics

Threads
1,123,258
Messages
5,600,564
Members
414,389
Latest member
MarkElla

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top