Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Modify macro to find cells beginning with A - help needed

Hello

I have had no success Googling to find my answer so perhaps someone can help
me?

I recorded a macro involving "Find" and run it from a button. It works but I
want to modify it to only search column A and find the first word beginning
with the letter A.
From this I will be able to change the code to search for B etc. and assign
it to another button.

Any help would be appreciated.

Kenny W
Using XP Pro and Office 2003





  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Modify macro to find cells beginning with A - help needed

Sub WheresTheA()
Dim r As Range
Set r = Intersect(Range("A:A"), ActiveSheet.UsedRange)
For Each rr In r
If Left(rr.Value, 1) = "a" Then
rr.Select
Exit Sub
End If
Next
End Sub
--
Gary''s Student - gsnu200906


"Forum Freak" wrote:

Hello

I have had no success Googling to find my answer so perhaps someone can help
me?

I recorded a macro involving "Find" and run it from a button. It works but I
want to modify it to only search column A and find the first word beginning
with the letter A.
From this I will be able to change the code to search for B etc. and assign
it to another button.

Any help would be appreciated.

Kenny W
Using XP Pro and Office 2003






  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Modify macro to find cells beginning with A - help needed

Why have a button for each letter? Just use one button and ask the user
which column they want to search....

Sub FindInColumn()
Dim FindColumn As String, FoundCell As Range
FindColumn = Application.InputBox("What column?", _
"GetColumn Letter", Type:=2)
On Error Resume Next
Set FoundCell = Columns(FindColumn).Find(What:="a*", _
MatchCase:=False, After:=Cells(Rows.Count, _
FindColumn), SearchOrder:=xlColumns, _
LookAt:=xlPart, SearchDirection:=xlNext, _
LookIn:=xlValues)
If Not FoundCell Is Nothing Then
MsgBox "Cell " & FoundCell.Address & " starts with 'a' or 'A'."
Else
MsgBox "No cells in Column '" & FindColumn & "' start with 'a' or 'A'."
End If
End Sub

By the way, the user can specify the column either by its letter or number
designation.

--
Rick (MVP - Excel)


"Forum Freak" wrote in message
...
Hello

I have had no success Googling to find my answer so perhaps someone can
help me?

I recorded a macro involving "Find" and run it from a button. It works but
I want to modify it to only search column A and find the first word
beginning with the letter A.
From this I will be able to change the code to search for B etc. and
assign it to another button.

Any help would be appreciated.

Kenny W
Using XP Pro and Office 2003






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Modify macro to find cells beginning with A - help needed

Don't use this routine... there is a flaw in it.

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
Why have a button for each letter? Just use one button and ask the user
which column they want to search....

Sub FindInColumn()
Dim FindColumn As String, FoundCell As Range
FindColumn = Application.InputBox("What column?", _
"GetColumn Letter", Type:=2)
On Error Resume Next
Set FoundCell = Columns(FindColumn).Find(What:="a*", _
MatchCase:=False, After:=Cells(Rows.Count, _
FindColumn), SearchOrder:=xlColumns, _
LookAt:=xlPart, SearchDirection:=xlNext, _
LookIn:=xlValues)
If Not FoundCell Is Nothing Then
MsgBox "Cell " & FoundCell.Address & " starts with 'a' or 'A'."
Else
MsgBox "No cells in Column '" & FindColumn & "' start with 'a' or 'A'."
End If
End Sub

By the way, the user can specify the column either by its letter or number
designation.

--
Rick (MVP - Excel)


"Forum Freak" wrote in message
...
Hello

I have had no success Googling to find my answer so perhaps someone can
help me?

I recorded a macro involving "Find" and run it from a button. It works
but I want to modify it to only search column A and find the first word
beginning with the letter A.
From this I will be able to change the code to search for B etc. and
assign it to another button.

Any help would be appreciated.

Kenny W
Using XP Pro and Office 2003







  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Modify macro to find cells beginning with A - help needed

This macro works correctly...

Sub FindInColumn()
Dim FindColumn As String, FoundCell As Range, FirstAddress As String
FindColumn = Application.InputBox("What column?", _
"GetColumn Letter", Type:=2)
On Error Resume Next
Set FoundCell = Columns(FindColumn).Find(What:="a*", _
MatchCase:=False, After:=Cells(Rows.Count, _
FindColumn), SearchOrder:=xlColumns, _
LookAt:=xlPart, SearchDirection:=xlNext, _
LookIn:=xlValues)
If Not FoundCell Is Nothing Then
If InStr(1, FoundCell.Value, "a", vbTextCompare) 1 Then
FirstAddress = FoundCell.Address
Do
Set FoundCell = Columns(FindColumn).FindNext(FoundCell)
Loop While InStr(1, FoundCell.Value, "a", vbTextCompare) 1 And _
FoundCell.Address < FirstAddress
End If
End If
If Not FoundCell Is Nothing Then
MsgBox "Cell " & FoundCell.Address & " starts with 'a' or 'A'."
Else
MsgBox "No cells in Column '" & FindColumn & "' start with 'a' or 'A'."
End If
End Sub

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
Don't use this routine... there is a flaw in it.

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
Why have a button for each letter? Just use one button and ask the user
which column they want to search....

Sub FindInColumn()
Dim FindColumn As String, FoundCell As Range
FindColumn = Application.InputBox("What column?", _
"GetColumn Letter", Type:=2)
On Error Resume Next
Set FoundCell = Columns(FindColumn).Find(What:="a*", _
MatchCase:=False, After:=Cells(Rows.Count, _
FindColumn), SearchOrder:=xlColumns, _
LookAt:=xlPart, SearchDirection:=xlNext, _
LookIn:=xlValues)
If Not FoundCell Is Nothing Then
MsgBox "Cell " & FoundCell.Address & " starts with 'a' or 'A'."
Else
MsgBox "No cells in Column '" & FindColumn & "' start with 'a' or
'A'."
End If
End Sub

By the way, the user can specify the column either by its letter or
number designation.

--
Rick (MVP - Excel)


"Forum Freak" wrote in message
...
Hello

I have had no success Googling to find my answer so perhaps someone can
help me?

I recorded a macro involving "Find" and run it from a button. It works
but I want to modify it to only search column A and find the first word
beginning with the letter A.
From this I will be able to change the code to search for B etc. and
assign it to another button.

Any help would be appreciated.

Kenny W
Using XP Pro and Office 2003










  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Modify macro to find cells beginning with A - help needed

WOW!

That did it and far more. Rather than the message box I just want the cell
activating but many thanks anyway :o)

Kenny


"Rick Rothstein" wrote in message
...
Why have a button for each letter? Just use one button and ask the user
which column they want to search....

Sub FindInColumn()
Dim FindColumn As String, FoundCell As Range
FindColumn = Application.InputBox("What column?", _
"GetColumn Letter", Type:=2)
On Error Resume Next
Set FoundCell = Columns(FindColumn).Find(What:="a*", _
MatchCase:=False, After:=Cells(Rows.Count, _
FindColumn), SearchOrder:=xlColumns, _
LookAt:=xlPart, SearchDirection:=xlNext, _
LookIn:=xlValues)
If Not FoundCell Is Nothing Then
MsgBox "Cell " & FoundCell.Address & " starts with 'a' or 'A'."
Else
MsgBox "No cells in Column '" & FindColumn & "' start with 'a' or 'A'."
End If
End Sub

By the way, the user can specify the column either by its letter or number
designation.

--
Rick (MVP - Excel)


"Forum Freak" wrote in message
...
Hello

I have had no success Googling to find my answer so perhaps someone can
help me?

I recorded a macro involving "Find" and run it from a button. It works
but I want to modify it to only search column A and find the first word
beginning with the letter A.
From this I will be able to change the code to search for B etc. and
assign it to another button.

Any help would be appreciated.

Kenny W
Using XP Pro and Office 2003








  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Modify macro to find cells beginning with A - help needed

Hi

I could not get this to work :o(

Kenny


"Gary''s Student" wrote in message
...
Sub WheresTheA()
Dim r As Range
Set r = Intersect(Range("A:A"), ActiveSheet.UsedRange)
For Each rr In r
If Left(rr.Value, 1) = "a" Then
rr.Select
Exit Sub
End If
Next
End Sub
--
Gary''s Student - gsnu200906


"Forum Freak" wrote:

Hello

I have had no success Googling to find my answer so perhaps someone can
help
me?

I recorded a macro involving "Find" and run it from a button. It works
but I
want to modify it to only search column A and find the first word
beginning
with the letter A.
From this I will be able to change the code to search for B etc. and
assign
it to another button.

Any help would be appreciated.

Kenny W
Using XP Pro and Office 2003








  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Modify macro to find cells beginning with A - help needed

You did my corrected code, right?

--
Rick (MVP - Excel)


"Forum Freak" wrote in message
...
WOW!

That did it and far more. Rather than the message box I just want the
cell activating but many thanks anyway :o)

Kenny


"Rick Rothstein" wrote in message
...
Why have a button for each letter? Just use one button and ask the user
which column they want to search....

Sub FindInColumn()
Dim FindColumn As String, FoundCell As Range
FindColumn = Application.InputBox("What column?", _
"GetColumn Letter", Type:=2)
On Error Resume Next
Set FoundCell = Columns(FindColumn).Find(What:="a*", _
MatchCase:=False, After:=Cells(Rows.Count, _
FindColumn), SearchOrder:=xlColumns, _
LookAt:=xlPart, SearchDirection:=xlNext, _
LookIn:=xlValues)
If Not FoundCell Is Nothing Then
MsgBox "Cell " & FoundCell.Address & " starts with 'a' or 'A'."
Else
MsgBox "No cells in Column '" & FindColumn & "' start with 'a' or
'A'."
End If
End Sub

By the way, the user can specify the column either by its letter or
number designation.

--
Rick (MVP - Excel)


"Forum Freak" wrote in message
...
Hello

I have had no success Googling to find my answer so perhaps someone can
help me?

I recorded a macro involving "Find" and run it from a button. It works
but I want to modify it to only search column A and find the first word
beginning with the letter A.
From this I will be able to change the code to search for B etc. and
assign it to another button.

Any help would be appreciated.

Kenny W
Using XP Pro and Office 2003









  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Modify macro to find cells beginning with A - help needed

Hi Rick

I modified your code to do exactly what I want. Im sure its not the best way
but it works.

My spreadsheet is a bit like an address book list and I have the buttons
(yes 26) at the top
Each search column B and each button searches for a specific letter.
Whilst your message box method cuts down on coding I felt it quicker for the
user to just click a button.

Many thanks again, you have saved me a hell of a lot of scrolling down!!!

Kenny

Modified code below.

Code starts xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxx

Sub FindInColumnB()
Dim FindColumn As String, FoundCell As Range, FirstAddress As String
'FindColumn = Application.InputBox("What column?", _ ''''this row removed
"GetColumn Letter", Type:=2)

FindColumn = "B"
On Error Resume Next
Set FoundCell = Columns(FindColumn).Find(What:="B*", _
MatchCase:=False, After:=Cells(Rows.Count, _
FindColumn), SearchOrder:=xlColumns, _
LookAt:=xlPart, SearchDirection:=xlNext, _
LookIn:=xlValues)
If Not FoundCell Is Nothing Then
If InStr(1, FoundCell.Value, "B", vbTextCompare) 1 Then
FirstAddress = FoundCell.Address
Do
Set FoundCell = Columns(FindColumn).FindNext(FoundCell)
Loop While InStr(1, FoundCell.Value, "B", vbTextCompare) 1 And _
FoundCell.Address < FirstAddress
End If
End If
If Not FoundCell Is Nothing Then

FoundCell.Activate

Else
MsgBox "No cells in Column '" & FindColumn & "' start with 'B'."
End If
End Sub

code ends
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
"Rick Rothstein" wrote in message
...
You did my corrected code, right?

--
Rick (MVP - Excel)


"Forum Freak" wrote in message
...
WOW!

That did it and far more. Rather than the message box I just want the
cell activating but many thanks anyway :o)

Kenny


"Rick Rothstein" wrote in message
...
Why have a button for each letter? Just use one button and ask the user
which column they want to search....

Sub FindInColumn()
Dim FindColumn As String, FoundCell As Range
FindColumn = Application.InputBox("What column?", _
"GetColumn Letter", Type:=2)
On Error Resume Next
Set FoundCell = Columns(FindColumn).Find(What:="a*", _
MatchCase:=False, After:=Cells(Rows.Count, _
FindColumn), SearchOrder:=xlColumns, _
LookAt:=xlPart, SearchDirection:=xlNext, _
LookIn:=xlValues)
If Not FoundCell Is Nothing Then
MsgBox "Cell " & FoundCell.Address & " starts with 'a' or 'A'."
Else
MsgBox "No cells in Column '" & FindColumn & "' start with 'a' or
'A'."
End If
End Sub

By the way, the user can specify the column either by its letter or
number designation.

--
Rick (MVP - Excel)


"Forum Freak" wrote in message
...
Hello

I have had no success Googling to find my answer so perhaps someone can
help me?

I recorded a macro involving "Find" and run it from a button. It works
but I want to modify it to only search column A and find the first word
beginning with the letter A.
From this I will be able to change the code to search for B etc. and
assign it to another button.

Any help would be appreciated.

Kenny W
Using XP Pro and Office 2003











Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to add the " symbol to the beginning and end of cells selected Stuart[_3_] Excel Programming 1 April 20th 08 11:05 PM
Macro needed (like find) doral Excel Discussion (Misc queries) 2 August 23rd 07 02:02 PM
modify a macro to apply to a specific range of cells Dave F Excel Discussion (Misc queries) 2 April 25th 07 03:00 AM
Find & Replace and Find & Insert macro help needed RS Excel Programming 2 January 29th 07 07:35 AM
Excel Find Macro Help Needed Bruce Johnson Excel Programming 2 September 27th 03 08:59 PM


All times are GMT +1. The time now is 09:08 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"