• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 289
  • Last Modified:

I need a macro which can popup a box and ask me for a text to search



Hi,

I need a macro which can popup a box and ask me for a text to search.And if found all the data with the same text should be colored and made bold.

regards
Sharath
0
bsharath
Asked:
bsharath
  • 3
  • 2
1 Solution
 
hiteshgoldeneyeCommented:
Sub a1()
Dim str1
str1= InputBox("SearchValue")
For i=1 to Sheet1.Usedrange.Rows.Count
   For j=1 to Sheet1.Usedrange.Rows.Count
       if Sheet1.Cells(i,j) = str1 then
          Sheet1.Cells(i,j).Font.Color = RGB(255,0,0)
          Sheet1.Cells(i,j).Font.Bold = True
      End if
  Next
Next

End Sub
0
 
bsharathAuthor Commented:
This is working fine .I think it is case sensitive.I want it to be colored and made bold found in any case.
What happens if there are two names the same.Can it be given a different color
0
 
hiteshgoldeneyeCommented:
try this
Sub a1()
Dim str1
Dim valuefound as Integer
valuefound = 1
str1= InputBox("SearchValue")
For i=1 to Sheet1.Usedrange.Rows.Count
   For j=1 to Sheet1.Usedrange.Rows.Count
       if UCase(Sheet1.Cells(i,j)) = UCase(str1) then
          Sheet1.Cells(i,j).Font.ColorIndex = valuefound
          Sheet1.Cells(i,j).Font.Bold = True
          valuefound = valuefound + 1
      End if
  Next
Next

End Sub
0
 
hiteshgoldeneyeCommented:
hey sharath i forgot one thing change the second line to
For j=1 to Sheet1.UsedRange.Columns.Count
0
 
bsharathAuthor Commented:
For j=1 to Sheet1.UsedRange.Columns.Count

What will the above do.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now