Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Macro to insert a cell after the selected cell

I have a huge database filled with data similar to the following set:

SCR SAW PI A HF RF
SCR SAW PI RF PI SCR
SCR SAW PI A HF RF
SCR SAW PI A HF RF

I'm looking for a macro that will prompt me for an input (ex. "SAW") and an
output (ex. "DB"). It would find every cell that contains the letters "SAW"
and insert a cell immediately to the right of it that contains the letters
"DB".

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Macro to insert a cell after the selected cell

Sub pointr()
inpt = Application.InputBox(Prompt:="enter input", Type:=2)
outp = Application.InputBox(Prompt:="enter output", Type:=2)
Set rPush = Nothing
For Each r In ActiveSheet.UsedRange
If r.Value = inpt Then
If rPush Is Nothing Then
Set rPush = r
Else
Set rPush = Union(rPush, r)
End If
End If
Next

rPush.Insert Shift:=xlToRight
rPush.Offset(0, 1).Value = outp
End Sub

--
Gary''s Student - gsnu200836
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Macro to insert a cell after the selected cell

This macro inserted a blank cell before the input cell. It didn't enter my
output information into the output cell, either.

"Gary''s Student" wrote:

Sub pointr()
inpt = Application.InputBox(Prompt:="enter input", Type:=2)
outp = Application.InputBox(Prompt:="enter output", Type:=2)
Set rPush = Nothing
For Each r In ActiveSheet.UsedRange
If r.Value = inpt Then
If rPush Is Nothing Then
Set rPush = r
Else
Set rPush = Union(rPush, r)
End If
End If
Next

rPush.Insert Shift:=xlToRight
rPush.Offset(0, 1).Value = outp
End Sub

--
Gary''s Student - gsnu200836

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Macro to insert a cell after the selected cell

Sorry...inserted at the wrong place:

Sub pointr()
inpt = Application.InputBox(Prompt:="enter input", Type:=2)
outp = Application.InputBox(Prompt:="enter output", Type:=2)
Set rPush = Nothing
For Each r In ActiveSheet.UsedRange
If r.Value = inpt Then
If rPush Is Nothing Then
Set rPush = r
Else
Set rPush = Union(rPush, r)
End If
End If
Next
rPush.Offset(0, 1).Insert Shift:=xlToRight
rPush.Offset(0, 1).Value = outp
End Sub

--
Gary''s Student - gsnu200836


"PointerMan" wrote:

This macro inserted a blank cell before the input cell. It didn't enter my
output information into the output cell, either.

"Gary''s Student" wrote:

Sub pointr()
inpt = Application.InputBox(Prompt:="enter input", Type:=2)
outp = Application.InputBox(Prompt:="enter output", Type:=2)
Set rPush = Nothing
For Each r In ActiveSheet.UsedRange
If r.Value = inpt Then
If rPush Is Nothing Then
Set rPush = r
Else
Set rPush = Union(rPush, r)
End If
End If
Next

rPush.Insert Shift:=xlToRight
rPush.Offset(0, 1).Value = outp
End Sub

--
Gary''s Student - gsnu200836

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Macro to insert a cell after the selected cell

That worked great! Thanks! One more question - if I wanted to do the same
thing but insert the new cell before the selected cell, which line would I
need to modify?

Thanks again!



"Gary''s Student" wrote:

Sorry...inserted at the wrong place:

Sub pointr()
inpt = Application.InputBox(Prompt:="enter input", Type:=2)
outp = Application.InputBox(Prompt:="enter output", Type:=2)
Set rPush = Nothing
For Each r In ActiveSheet.UsedRange
If r.Value = inpt Then
If rPush Is Nothing Then
Set rPush = r
Else
Set rPush = Union(rPush, r)
End If
End If
Next
rPush.Offset(0, 1).Insert Shift:=xlToRight
rPush.Offset(0, 1).Value = outp
End Sub

--
Gary''s Student - gsnu200836


"PointerMan" wrote:

This macro inserted a blank cell before the input cell. It didn't enter my
output information into the output cell, either.

"Gary''s Student" wrote:

Sub pointr()
inpt = Application.InputBox(Prompt:="enter input", Type:=2)
outp = Application.InputBox(Prompt:="enter output", Type:=2)
Set rPush = Nothing
For Each r In ActiveSheet.UsedRange
If r.Value = inpt Then
If rPush Is Nothing Then
Set rPush = r
Else
Set rPush = Union(rPush, r)
End If
End If
Next

rPush.Insert Shift:=xlToRight
rPush.Offset(0, 1).Value = outp
End Sub

--
Gary''s Student - gsnu200836



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Macro to insert a cell after the selected cell

We change the last two lines:

Sub pointr()
inpt = Application.InputBox(Prompt:="enter input", Type:=2)
outp = Application.InputBox(Prompt:="enter output", Type:=2)
Set rPush = Nothing
For Each r In ActiveSheet.UsedRange
If r.Value = inpt Then
If rPush Is Nothing Then
Set rPush = r
Else
Set rPush = Union(rPush, r)
End If
End If
Next
rPush.Insert Shift:=xlToRight
rPush.Offset(0, -1).Value = outp
End Sub
--
Gary''s Student - gsnu200836


"PointerMan" wrote:

That worked great! Thanks! One more question - if I wanted to do the same
thing but insert the new cell before the selected cell, which line would I
need to modify?

Thanks again!



"Gary''s Student" wrote:

Sorry...inserted at the wrong place:

Sub pointr()
inpt = Application.InputBox(Prompt:="enter input", Type:=2)
outp = Application.InputBox(Prompt:="enter output", Type:=2)
Set rPush = Nothing
For Each r In ActiveSheet.UsedRange
If r.Value = inpt Then
If rPush Is Nothing Then
Set rPush = r
Else
Set rPush = Union(rPush, r)
End If
End If
Next
rPush.Offset(0, 1).Insert Shift:=xlToRight
rPush.Offset(0, 1).Value = outp
End Sub

--
Gary''s Student - gsnu200836


"PointerMan" wrote:

This macro inserted a blank cell before the input cell. It didn't enter my
output information into the output cell, either.

"Gary''s Student" wrote:

Sub pointr()
inpt = Application.InputBox(Prompt:="enter input", Type:=2)
outp = Application.InputBox(Prompt:="enter output", Type:=2)
Set rPush = Nothing
For Each r In ActiveSheet.UsedRange
If r.Value = inpt Then
If rPush Is Nothing Then
Set rPush = r
Else
Set rPush = Union(rPush, r)
End If
End If
Next

rPush.Insert Shift:=xlToRight
rPush.Offset(0, 1).Value = outp
End Sub

--
Gary''s Student - gsnu200836

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
Insert selected cell value into next cell in range that is empty Guy[_2_] Excel Worksheet Functions 6 January 3rd 09 10:08 PM
Macro to transfer contents of 'Selected' cell to alternate cell. Gryndar Excel Worksheet Functions 7 December 20th 08 09:58 PM
'IF' Macro to insert cell contents to alternate cell if cell not e Gryndar Excel Worksheet Functions 6 December 20th 08 05:02 PM
how do I insert the address of a selected cell into a fixed cell cox Excel Discussion (Misc queries) 2 May 27th 06 07:44 PM
Macro to take selected cells times a selected cell Craig Excel Programming 4 October 24th 05 12:54 AM


All times are GMT +1. The time now is 09:38 AM.

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"