Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default How to insert Data

Hi, All

can you tell me, how create macro/vba to insert data to several row.
Which have following criteria:

if the data between first data and end data from column A, then that
data insert to column A
if the data between first data and end data from column B, then that
data insert to column B
if the data between first data and end data from column C, then that
data insert to column C
A B C D <- column for input data
1 10 22
4 12 25
5 15 26
6 17 40

if in column D I input 13 then the number that i have input insert to
column B

Regards


ARDI

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default How to insert Data


Ardi,

Try this. You need to add code to select data from column D. My
"test" routine calls the macro with a value (2 in the example).

I assume data starts in row 2. If this not true, change the rngA,B and C
statements.

HTH

Sub test()
Call InsertInColumn(2)
End Sub


Sub InsertInColumn(newValue)
Dim rngA As Range, rngB As Range, rngC As Range
Dim lastrow As Long
Dim ws1 As Worksheet
Set ws1 = Worksheets("sheet1")
With ws1
Set rngA = Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row)
Set rngB = Range("B2:B" & Cells(Rows.Count, "B").End(xlUp).Row)
Set rngC = Range("C2:C" & Cells(Rows.Count, "B").End(xlUp).Row)
End With
If newValue < Application.Max(rngA) Then
Call FindInsertRow(rngA, newValue)
Else
If newValue < Application.Max(rngB) Then
Call FindInsertRow(rngB, newValue)
Else
Call FindInsertRow(rngC, newValue)
End If
End If
End Sub

Sub FindInsertRow(rng, nv)
res = Application.Match(nv, rng, 1)
If IsError(res) Then res = 0
rng(res + 1).Select
Selection.Insert Shift:=xlDown
ActiveCell.FormulaR1C1 = nv
End Sub


"ardi" wrote:

Hi, All

can you tell me, how create macro/vba to insert data to several row.
Which have following criteria:

if the data between first data and end data from column A, then that
data insert to column A
if the data between first data and end data from column B, then that
data insert to column B
if the data between first data and end data from column C, then that
data insert to column C
A B C D <- column for input data
1 10 22
4 12 25
5 15 26
6 17 40

if in column D I input 13 then the number that i have input insert to
column B

Regards


ARDI


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default How to insert Data

NOTE: I have assumed no duplicates- if there are then change

If newValue < Application.Max(rngA) Then to

If newValue <= Application.Max(rngA) Then

Repeat for B and C



"Toppers" wrote:


Ardi,

Try this. You need to add code to select data from column D. My
"test" routine calls the macro with a value (2 in the example).

I assume data starts in row 2. If this not true, change the rngA,B and C
statements.

HTH

Sub test()
Call InsertInColumn(2)
End Sub


Sub InsertInColumn(newValue)
Dim rngA As Range, rngB As Range, rngC As Range
Dim lastrow As Long
Dim ws1 As Worksheet
Set ws1 = Worksheets("sheet1")
With ws1
Set rngA = Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row)
Set rngB = Range("B2:B" & Cells(Rows.Count, "B").End(xlUp).Row)
Set rngC = Range("C2:C" & Cells(Rows.Count, "B").End(xlUp).Row)
End With
If newValue < Application.Max(rngA) Then
Call FindInsertRow(rngA, newValue)
Else
If newValue < Application.Max(rngB) Then
Call FindInsertRow(rngB, newValue)
Else
Call FindInsertRow(rngC, newValue)
End If
End If
End Sub

Sub FindInsertRow(rng, nv)
res = Application.Match(nv, rng, 1)
If IsError(res) Then res = 0
rng(res + 1).Select
Selection.Insert Shift:=xlDown
ActiveCell.FormulaR1C1 = nv
End Sub


"ardi" wrote:

Hi, All

can you tell me, how create macro/vba to insert data to several row.
Which have following criteria:

if the data between first data and end data from column A, then that
data insert to column A
if the data between first data and end data from column B, then that
data insert to column B
if the data between first data and end data from column C, then that
data insert to column C
A B C D <- column for input data
1 10 22
4 12 25
5 15 26
6 17 40

if in column D I input 13 then the number that i have input insert to
column B

Regards


ARDI


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default How to insert Data

Sorry .. spotted a typo:

Set rngC = Range("C2:C" & Cells(Rows.Count, "B").End(xlUp).Row)

should be

Set rngC = Range("C2:C" & Cells(Rows.Count, "C").End(xlUp).Row)


"Toppers" wrote:

NOTE: I have assumed no duplicates- if there are then change

If newValue < Application.Max(rngA) Then to

If newValue <= Application.Max(rngA) Then

Repeat for B and C



"Toppers" wrote:


Ardi,

Try this. You need to add code to select data from column D. My
"test" routine calls the macro with a value (2 in the example).

I assume data starts in row 2. If this not true, change the rngA,B and C
statements.

HTH

Sub test()
Call InsertInColumn(2)
End Sub


Sub InsertInColumn(newValue)
Dim rngA As Range, rngB As Range, rngC As Range
Dim lastrow As Long
Dim ws1 As Worksheet
Set ws1 = Worksheets("sheet1")
With ws1
Set rngA = Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row)
Set rngB = Range("B2:B" & Cells(Rows.Count, "B").End(xlUp).Row)
Set rngC = Range("C2:C" & Cells(Rows.Count, "B").End(xlUp).Row)
End With
If newValue < Application.Max(rngA) Then
Call FindInsertRow(rngA, newValue)
Else
If newValue < Application.Max(rngB) Then
Call FindInsertRow(rngB, newValue)
Else
Call FindInsertRow(rngC, newValue)
End If
End If
End Sub

Sub FindInsertRow(rng, nv)
res = Application.Match(nv, rng, 1)
If IsError(res) Then res = 0
rng(res + 1).Select
Selection.Insert Shift:=xlDown
ActiveCell.FormulaR1C1 = nv
End Sub


"ardi" wrote:

Hi, All

can you tell me, how create macro/vba to insert data to several row.
Which have following criteria:

if the data between first data and end data from column A, then that
data insert to column A
if the data between first data and end data from column B, then that
data insert to column B
if the data between first data and end data from column C, then that
data insert to column C
A B C D <- column for input data
1 10 22
4 12 25
5 15 26
6 17 40

if in column D I input 13 then the number that i have input insert to
column B

Regards


ARDI


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default How to insert Data

Thanks for your help

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I insert a row after every row of data in XL? jetanddug Excel Discussion (Misc queries) 5 November 2nd 09 04:25 PM
MULTIPLE DATA - How to insert new data into existing data.... Rodorodo Excel Discussion (Misc queries) 0 December 15th 06 11:50 PM
insert data Smoop Excel Worksheet Functions 1 October 19th 06 08:32 AM
Use excel to insert data at the bottom of existing data Mike Lines Excel Programming 1 October 7th 05 03:43 PM
Import Data: on insert, shift data down and not right Raminhos Excel Discussion (Misc queries) 1 February 17th 05 02:08 PM


All times are GMT +1. The time now is 02:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"