Minggu, 24 Juli 2011

[ExcelVBA] Re: VBA 'Like' using Cell Value

 

Charlie,

I think that your code is changing all cells because of what you've got in cell P17. If I put a star (*) in P17, everything is changed, if I put something else, only the appropriate cell is changed. To change more than one font property, try the following:

Sub TryThis()
For i = 1 To 10 'whatever increment you're using
If LCase(Range("A" & i).Value) Like (Range("p17").Value) Then
With Range("b" & i).Font
.Size = 20
.Italic = True
End With
End If
Next i
End Sub

Dave Gathmann

--- In ExcelVBA@yahoogroups.com, railroads@... wrote:
>
> Hi
>
>
> I want to replace this line of code that looks for "Chapter":
>
> If LCase(Range("A" & i).Value) Like "chapter*" Then Range("b" & i).Font.size = 20
>
> This works well.
>
> But I need the value in a cell to be looked for. Say cdell P17. Cell changes value from time to time.
>
> Have tried this code below but the code seems to miss the Like (Range("P17") part and changes all rows to size = 20.
>
> If LCase(Range("A" & i).Value) Like (Range("p17").Value) Then Range("b" & i).Font.size = 20
>
> Is there something not quite right?
>
> Also I would like to add code re the font size to include Italics. Have tried this below but the & seems to be the problem. How do I include extra format codes.
>
> .............Font.size = 20 & Font.Italic = True
>
> Thanks
>
> Charlie
>

__._,_.___
Recent Activity:
----------------------------------
Be sure to check out TechTrax Ezine for many, free Excel VBA articles! Go here: http://www.mousetrax.com/techtrax to enter the ezine, then search the ARCHIVES for EXCEL VBA.

----------------------------------
Visit our ExcelVBA group home page for more info and support files:
http://groups.yahoo.com/group/ExcelVBA

----------------------------------
More free tutorials and resources available at:
http://www.mousetrax.com

----------------------------------
MARKETPLACE

Stay on top of your group activity without leaving the page you're on - Get the Yahoo! Toolbar now.

.

__,_._,___

Tidak ada komentar:

Posting Komentar