Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Junior Member
 
Posts: 9
Default Macro to search for a value and insert new row

I need a line in a macro to search column D, find value '90601' and copy the row that has that value in column to a new row and change '90601' to another value. There will be multiple rows with this value, but the other columns will contain other information. Can anybody help with this? I have attached the spreadsheet I am working with. Thanks!!
Attached Files
File Type: zip for help.zip (12.0 KB, 37 views)
  #2   Report Post  
Junior Member
 
Posts: 9
Default

New value needs to be 20150


Quote:
Originally Posted by ksquirt View Post
I need a line in a macro to search column D, find value '90601' and copy the row that has that value in column to a new row and change '90601' to another value. There will be multiple rows with this value, but the other columns will contain other information. Can anybody help with this? I have attached the spreadsheet I am working with. Thanks!!
  #3   Report Post  
Junior Member
 
Posts: 9
Cool

We have a macro that adds a row, so I am starting with it and I need to tweak it. Here's what I have so far (I figured with a lot of views I should keep you updated as to what I'm doing). What I'm looking at now is how to cycle thru all the rows as the amount of rows will change. I also need to paste the new number in column D. I have not tested this yet as it is in a larger macro.

Range("D8").Select

If ActiveCell.Value = "90601" Then
ActiveCell.Offset(1, 0).Select
Selection.EntireRow.Insert
ActiveCell.Offset(-1, 0).Select
Selection.EntireRow.Copy
ActiveCell.Offset(1, 0).Select
ActiveCell.PasteSpecial
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveSheet.Paste
Application.CutCopyMode = False
Else



Quote:
Originally Posted by ksquirt View Post
I need a line in a macro to search column D, find value '90601' and copy the row that has that value in column to a new row and change '90601' to another value. There will be multiple rows with this value, but the other columns will contain other information. Can anybody help with this? I have attached the spreadsheet I am working with. Thanks!!
  #4   Report Post  
Junior Member
 
Posts: 9
Question

After more searching thru this site and others here is my current piece of the macro. The problem I'm running into now is that I need certain cell removed. Right now it's removing the whole column. How do I get it to just remove the 'dollars' for the rows with 21050 in column D? and the 'hours'for all other rows? See attached spreadsheet.

Dim LSearchRow As Integer
LSearchRow = 6


While Len(Range("A" & CStr(LSearchRow)).Value) 0

'If Column D = "90601", copy entire row
If Range("D" & CStr(LSearchRow)).Value = "90601" Then
Range("D" & CStr(LSearchRow)).EntireRow.Copy
'Insert copied Row below the original
Range("D" & CStr(LSearchRow)).EntireRow.Insert Shift:=xlDown
'Change values in Columns D on new row to 20150
Range("D" & CStr(LSearchRow + 1)) = "20150"

End If


'If Column D = "20150", remove dollars columns
If Range("D" & CStr(LSearchRow)).Value = "20150" Then
Range("G:G,I:I,K:K,M:M,O:O,Q:Q,S:S,U:U,W:W,Y:Y,AA: AA,AC:AC,AE:AE,AG:AG,AI:AI,AK:AK,AM:AM,AO:AO,AQ:AQ ,AS:AS,AU:AU,AW:AW,AY:AY").Cell.Delete

'Selection.Delete Shift:=xlToLeft
End If
'If Column D does not equal "20150", remove hours columns (*using ' to get part of the code to not work while I focus on other parts*)
'If Range("D" & CStr(LSearchRow)).Value < "20150" Then
' Range("F:F,H:H,J:J,L:L,N:N,P:P,R:R,T:T,V:V,X:X,Z:Z ,AB:AB,AD:AD,AF:AF,AH:AH,AJ:AJ,AL:AL,AN:AN,AP:AP,A R:AR,AT:AT,AV:AV,AX:AX,AZ:AZ").Select
' Selection.Delete Shift:=xlToLeft

'End If
'Increment Search row variable
LSearchRow = LSearchRow + 1

'Loop
Wend

Last edited by ksquirt : July 17th 12 at 03:14 PM
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
Search & insert Ticotion Excel Programming 6 December 21st 09 11:35 PM
VBA to Search, Insert Column and Sum Richard Excel Programming 4 May 11th 07 06:36 AM
search for worksheet, insert new if doesn't exist cereldine[_19_] Excel Programming 2 April 21st 06 05:10 PM
Search & Replace to insert alt+ wennerberg Excel Discussion (Misc queries) 7 September 29th 05 07:37 PM
Excel – Macro Problem – Find/Search and Insert Aussiexcel[_5_] Excel Programming 0 August 31st 04 07:21 AM


All times are GMT +1. The time now is 01:25 PM.

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

About Us

"It's about Microsoft Excel"