Solved

Search and Replace VBA in Excel

Posted on 2011-03-02
2
295 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 50

Accepted Solution

by:
Dave Brett earned 500 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

Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

752 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