?
Solved

Search and Replace VBA in Excel

Posted on 2011-03-02
2
Medium Priority
?
305 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 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

This article describes a serious pitfall that can happen when deleting shapes using VBA.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
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…

719 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