Solved

Search and Replace VBA in Excel

Posted on 2011-03-02
2
301 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

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 …
This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

617 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