Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Search and Replace VBA in Excel

Posted on 2011-03-02
2
Medium Priority
?
310 Views
Last Modified: 2012-05-11
I'm looking for a block of code that will search row one of "Sheet1" to find a value that is equal to left(Main!B2,3).  One value has been found, I need it to set all number values in that column to ZERO.

So if Main!B2 was "March" and Sheet1!D1 ended up matching left(Main!B2,3), then all values in that column starting in row 2 would be ZERO.

To apply this to the entire column containing data, I probably need to incorporate something like this:
Private Sub AutoFill()
Dim LastRowInA As Long

Dim r As Range
Set r = Range("Match of left(Main!B2")

LastRowInA = Range("A1048576").End(xlUp).Row

r.AutoFill Destination:=Range("Match of left(Main!B2" & LastRowInA)

End Sub

Open in new window

Obviously my code above is wrong, but it should give you an idea of what I'm looking to accomplish.  Thanks for any help!  Also I attached a sample spreadsheet.
Example.xlsx
0
Comment
Question by:KP_SoCal
2 Comments
 
LVL 50

Accepted Solution

by:
Dave Brett earned 2000 total points
ID: 35023737
wrong sample? :)

try this

Cheers

Dave
Sub Fill()
Dim ws As Worksheet
Dim rng1 As Range
Set ws = Sheets("Sheet1")
Set rng1 = ws.Rows(1).Find(Left$(Sheets("Main").[b2], 3), , xlValues, xlWhole)
If Not rng1 Is Nothing Then ws.Range(ws.Cells(2, rng1.Column), ws.Cells(Rows.Count, rng1.Column).End(xlUp)) = 0
End Sub

Open in new window

sampel.xlsm
0
 

Author Closing Comment

by:KP_SoCal
ID: 35023859
Perfecto!  Thanks so much and yes, I did attach the wrong sample. LOL

=)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Quickbooks hosting can do wonders to your enterprise but considering the points elaborated in the article which will help you to better analyze the outcomes. So scan your business, its needs and then move to the new world of limitless benefits.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question