Find and replace with excel macros
Closed
Rachel
-
Mar 28, 2011 at 05:36 PM
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - Mar 31, 2011 at 11:11 AM
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - Mar 31, 2011 at 11:11 AM
Related:
- Find and replace with excel macros
- Excel online macros - Guide
- Excel mod apk for pc - Download - Spreadsheets
- Kernel for excel repair - Download - Backup and recovery
- Replace abbreviation - Guide
- Vat calculation excel - Guide
1 response
RWomanizer
Posts
365
Registration date
Monday February 7, 2011
Status
Contributor
Last seen
September 30, 2013
120
Mar 29, 2011 at 01:37 AM
Mar 29, 2011 at 01:37 AM
Hi Rachel,
try to record a macro to see if you search a value in give cell and copy the row in which result found, what code is generated.
try to record a macro to see if you search a value in give cell and copy the row in which result found, what code is generated.
Mar 29, 2011 at 02:31 PM
ActiveWindow.LargeScroll ToRight:=-1
Sheets("Input Sheet").Select
Range("B8").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Calculation").Select
Range("C22").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Mar 31, 2011 at 11:11 AM
'you scolled the window
ActiveWindow.LargeScroll ToRight:=-1
' you selected this shee
Sheets("Input Sheet").Select
'you selected this cell
Range("B8").Select
'internal excel prep for copy
Application.CutCopyMode = False
'actual copy
Selection.Copy
'this sheet is selected
Sheets("Calculation").Select
'this cell on calc sheet is select
Range("C22").Select
'from last selected cell, till the last used cell on rights, the cells are selected
Range(Selection, Selection.End(xlToRight)).Select
'from last selected range, till the last used cell on rights, the cells are selected
Range(Selection, Selection.End(xlToRight)).Select
'internal excel prep for copy
Application.CutCopyMode = False
'actual copy
Selection.Copy
'actual paste as values
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
How ever, at the best this is only a template. I think this appoach would be a tad better
Sub doFindAndPasteSpecial() Dim sInputSheet As String Dim rngInputRange As Range Dim sOutputSheet As String Dim rngSearchRange As Range Dim rngOutputRange As Range sInputSheet = "Input Sheet" 'name of the input sheet sOutputSheet = "Calculation" 'name of the output/paste sheet 'this is the cell where the value to be search is always Set rngInputRange = Sheets(sInputSheet).Range(Cells(8, "B")) 'if the lookup cell is blank, then exit sub If (rngInputRange.Value = vbNullString) Then Exit Sub 'setting the range to be searched on output sheet Set rngSearchRange = Sheets(sOutputSheet).Range("C1:C" & Rows.Count) With rngSearchRange Set rngOutputRange = Nothing 'attempting to find the cell that has the value Set rngOutputRange = .Find(What:=sInputRange.Value, _ After:=.Cells(1, 1), _ Lookat:=xlWhole, _ SearchDirection:=xlNext, _ MatchCase:=False) 'no dice. getting out of routine If (rngOutputRange Is Nothing) Then Exit Sub End With 'EUREKA!!!!! FOUND IT With Sheets(sOutputSheet).Rows(rngOutputRange.Row) Application.CutCopyMode = False .Copy 'copying the row 'pasting the row back .PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False Application.CutCopyMode = False End With End Sub