Please help me explain Target(index) in Worksheet_Change Event?

hunghung

New Member
Joined
Feb 27, 2018
Messages
12
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi, I am new to VBA and this is the first time I post a thread in the forum. Hope you in the forum help me.
I have trouble with one problem. Sorry for my bad English

I have data containing 3 columns Code, Name and Date with alternate blank rows as below. I want a code that can automatically insert more a blank row down when I enter data into yellow highlighted blank rows.
BCDE
1
2CodeNameDate
3
4TD20THEP TRON Ø2012/4/2014
5
6TD22THEP TRON Ø2211/1/2014
7
8TD24THEP TRON Ø2411/1/2014
9
10TD26THEP TRON Ø2811/1/2014
11

<tbody>
</tbody>
Sheet1
A online friend helped me create this code but no explain his code for me.
Code:
Option Explicit


Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Not Intersect(Target, [D2:D1000]) Is Nothing Then
   Application.EnableEvents = False
      If Target(2) <> "" Then Target(2).EntireRow.Insert
   Application.EnableEvents = True
End If
End Sub

First thing, I want people in the forum please explain what is the meaning of Target(2) and the usage of it.
Secondly, if possible, is there any other solution for this problem? I wanna see your other solutions.
Thanks in advance.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Hi hunghung,
The target cell is the cell that is changed
target(2) is the cell below
target(,2) is the column to right
and target(2,2) is the diagonal cell
target(1) is the same as target(1,1) or target (,1)

so your code is looking form a blank cell below the entry data and if is not balnk adds a new row.
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,582
Members
449,089
Latest member
Motoracer88

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
Back
Top