Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 11th, 2016, 03:25 AM
Authorized User
 
Join Date: Apr 2009
Posts: 23
Thanks: 1
Thanked 0 Times in 0 Posts
Default Find and Replace Method

Dear all,
I have deployed a Find method but that has made the code bit lengthier. Instead I want to use the find and replace methods using an array variable. My approach would be to:

1) First find a list of values stored within my srchString variable
2) Select all those columns
3) Cut all those columns
4) Move them to extreme left using Insert Shift:=xlToRight method

Note that srchString and replaceString variables are there just for reference for the time being but I intend to use them with find and replace methods.

Thanks in advance.

SMI//


Code:
Dim xRows, finalRow  As Single
Dim StartDate, EndDate As Date

xRows = Rows.Count
finalRow = Range("A" & xRows).End(xlUp).Row

StartDate = Application.WorksheetFunction.Min(Range(Cells(2, 2), Cells(finalRow, 2)))
EndDate = Application.WorksheetFunction.Max(Range(Cells(2, 2), Cells(finalRow, 2)))

srchString = Array("invoice_number", "invoice_date", "Certificate/Report_No", "Bill To Customer", "original_order_number", "item_description", _
"rev_seg04_activity", "oh_attribute13", "header_dff_value11", "oh_attribute15", "pre_tax_amount_func", "tax_charged_func", "total_amount_func")

replaceString = Array("Invoice #", "Invoice Date", "OGC Job#", "Customer", "Boss Order#", "Item Type", _
"GFM Code", "Vessel", "Product", "Division", "Net Amount", "Tax Amount", "Total Amount (PKR)")

With ActiveSheet.Range("a1:ho1")

    Set C = .Find("Certificate/Report_No", LookIn:=xlValues)
    Range(C.Address).EntireColumn.Cut
    Columns("C:C").Insert Shift:=xlToRight
    '--------------------------------------------
    Set C = .Find("Bill To Customer", LookIn:=xlValues)
    Range(C.Address).EntireColumn.Cut
    Columns("D:D").Insert Shift:=xlToRight
    '--------------------------------------------
    Set C = .Find("original_order_number", LookIn:=xlValues)
    Range(C.Address).EntireColumn.Cut
    Columns("E:E").Insert Shift:=xlToRight
    '--------------------------------------------
    Set C = .Find("item_description", LookIn:=xlValues)
    Range(C.Address).EntireColumn.Cut
    Columns("F:F").Insert Shift:=xlToRight
    '--------------------------------------------
    Set C = .Find("rev_seg04_activity", LookIn:=xlValues)
    Range(C.Address).EntireColumn.Cut
    Columns("G:G").Insert Shift:=xlToRight
    '--------------------------------------------
    Set C = .Find("header_dff_value11", LookIn:=xlValues)
    Range(C.Address).EntireColumn.Cut
    Columns("H:H").Insert Shift:=xlToRight
    '--------------------------------------------
    Set C = .Find("oh_attribute13", LookIn:=xlValues)
    Range(C.Address).EntireColumn.Cut
    Columns("I:I").Insert Shift:=xlToRight
    '--------------------------------------------
    Set C = .Find("oh_attribute15", LookIn:=xlValues)
    Range(C.Address).EntireColumn.Cut
    Columns("J:J").Insert Shift:=xlToRight
    '--------------------------------------------
    Set C = .Find("pre_tax_amount_func", LookIn:=xlValues)
    Range(C.Address).EntireColumn.Cut
    Columns("K:K").Insert Shift:=xlToRight
    '--------------------------------------------
    Set C = .Find("tax_charged_func", LookIn:=xlValues)
    Range(C.Address).EntireColumn.Cut
    Columns("L:L").Insert Shift:=xlToRight
    '--------------------------------------------
    Set C = .Find("total_amount_func", LookIn:=xlValues)
    Range(C.Address).EntireColumn.Cut
    Columns("M:M").Insert Shift:=xlToRight


 End With





Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace Method in JavaScript kwilliams Javascript How-To 2 April 3rd, 2007 12:50 PM
Replace method don't work with [ ] / skyler Javascript How-To 1 December 30th, 2006 10:04 AM
String.replace() method JohnD Javascript 0 August 20th, 2004 06:46 AM
Create a find and a find and replace in VB.NET snowy0 VB How-To 0 January 26th, 2004 07:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.