Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default Can I write a macro to ask for a specific number?

I have a worksheet that has numerous columns and rows. I would like to write
a macro looking for a number then format the cell. I would like to set up a
button to do this and ask for a different number each time.
--
DMM
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Can I write a macro to ask for a specific number?

put a button from the control toolbox toolbar on the sheet. Double click on
it to take you to the click event (or right click and select view code).

Put in code like the below pseudo code:

Private Sub Commandbutton1_Click()
dim ans as Long, rng as Range

ans = application.Inputbox("Enter an integer to format",type:=1)
set rng = cells.Find(ans)
if not rng is nothing then
rng.NumberFormat = "#,##0"
else
msgbox ans & " was not found"
End if
End Sub

now go back to excel and take the sheet out of design mode (click on the
depressed button on the control toolbox toolbar with the ruler and drawing
triangle - or their may be a separate floating toolbar with this same
button).

--
Regards,
Tom Ogilvy

"soconfused" wrote:

I have a worksheet that has numerous columns and rows. I would like to write
a macro looking for a number then format the cell. I would like to set up a
button to do this and ask for a different number each time.
--
DMM

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default Can I write a macro to ask for a specific number?

Hi Tom,

I am doing this, but it's not finding the number in the worksheet? I'm sure
I'm doing something wrong.
--
DMM


"Tom Ogilvy" wrote:

put a button from the control toolbox toolbar on the sheet. Double click on
it to take you to the click event (or right click and select view code).

Put in code like the below pseudo code:

Private Sub Commandbutton1_Click()
dim ans as Long, rng as Range

ans = application.Inputbox("Enter an integer to format",type:=1)
set rng = cells.Find(ans)
if not rng is nothing then
rng.NumberFormat = "#,##0"
else
msgbox ans & " was not found"
End if
End Sub

now go back to excel and take the sheet out of design mode (click on the
depressed button on the control toolbox toolbar with the ruler and drawing
triangle - or their may be a separate floating toolbar with this same
button).

--
Regards,
Tom Ogilvy

"soconfused" wrote:

I have a worksheet that has numerous columns and rows. I would like to write
a macro looking for a number then format the cell. I would like to set up a
button to do this and ask for a different number each time.
--
DMM

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Can I write a macro to ask for a specific number?

I enriched the macro and tested it - worked fine for me:

Private Sub Commandbutton1_Click()
Dim ans As Long, rng As Range

ans = Application.InputBox("Enter an integer to format", Type:=1)
Set rng = Cells.Find(What:=ans, _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not rng Is Nothing Then
MsgBox ans & " found at " & rng.Address
rng.NumberFormat = "#,##0"
Else
MsgBox ans & " was not found"
End If
End Sub

If the number is produced by a formula, change xlFormulas to xlValues

If the number isn't an integer or if it is produced by a formula, make sure
you are searching for the exact number - sometimes, a number like 16 might be
stored or calculated as 15.9999999999999 as an example.

--
Regards,
Tom Ogilvy


"soconfused" wrote:

Hi Tom,

I am doing this, but it's not finding the number in the worksheet? I'm sure
I'm doing something wrong.
--
DMM


"Tom Ogilvy" wrote:

put a button from the control toolbox toolbar on the sheet. Double click on
it to take you to the click event (or right click and select view code).

Put in code like the below pseudo code:

Private Sub Commandbutton1_Click()
dim ans as Long, rng as Range

ans = application.Inputbox("Enter an integer to format",type:=1)
set rng = cells.Find(ans)
if not rng is nothing then
rng.NumberFormat = "#,##0"
else
msgbox ans & " was not found"
End if
End Sub

now go back to excel and take the sheet out of design mode (click on the
depressed button on the control toolbox toolbar with the ruler and drawing
triangle - or their may be a separate floating toolbar with this same
button).

--
Regards,
Tom Ogilvy

"soconfused" wrote:

I have a worksheet that has numerous columns and rows. I would like to write
a macro looking for a number then format the cell. I would like to set up a
button to do this and ask for a different number each time.
--
DMM

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default Can I write a macro to ask for a specific number?

Hi Tom,

I am getting the number that I want now, but it's just telling me where to
find it. I want it to find it and change the fill color to no color.
--
DMM


"Tom Ogilvy" wrote:

I enriched the macro and tested it - worked fine for me:

Private Sub Commandbutton1_Click()
Dim ans As Long, rng As Range

ans = Application.InputBox("Enter an integer to format", Type:=1)
Set rng = Cells.Find(What:=ans, _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not rng Is Nothing Then
MsgBox ans & " found at " & rng.Address
rng.NumberFormat = "#,##0"
Else
MsgBox ans & " was not found"
End If
End Sub

If the number is produced by a formula, change xlFormulas to xlValues

If the number isn't an integer or if it is produced by a formula, make sure
you are searching for the exact number - sometimes, a number like 16 might be
stored or calculated as 15.9999999999999 as an example.

--
Regards,
Tom Ogilvy


"soconfused" wrote:

Hi Tom,

I am doing this, but it's not finding the number in the worksheet? I'm sure
I'm doing something wrong.
--
DMM


"Tom Ogilvy" wrote:

put a button from the control toolbox toolbar on the sheet. Double click on
it to take you to the click event (or right click and select view code).

Put in code like the below pseudo code:

Private Sub Commandbutton1_Click()
dim ans as Long, rng as Range

ans = application.Inputbox("Enter an integer to format",type:=1)
set rng = cells.Find(ans)
if not rng is nothing then
rng.NumberFormat = "#,##0"
else
msgbox ans & " was not found"
End if
End Sub

now go back to excel and take the sheet out of design mode (click on the
depressed button on the control toolbox toolbar with the ruler and drawing
triangle - or their may be a separate floating toolbar with this same
button).

--
Regards,
Tom Ogilvy

"soconfused" wrote:

I have a worksheet that has numerous columns and rows. I would like to write
a macro looking for a number then format the cell. I would like to set up a
button to do this and ask for a different number each time.
--
DMM

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 which deletes a row, when it finds a specific number Spiros Excel Discussion (Misc queries) 3 December 4th 07 05:43 AM
INserting Specific Number of Rows via macro [email protected] Links and Linking in Excel 1 November 14th 06 09:56 PM
how to write function to find max deviation from specific number . barbdee Excel Worksheet Functions 2 December 16th 05 02:10 AM
is it possible to execute write to the fields in another .xsl form a macro in another .xsl? e.g. some way to load another .xsl into an .xsl macro and write to its data? Daniel Excel Worksheet Functions 1 June 23rd 05 11:38 PM
Macro to copy down specific number of rows JA Excel Programming 4 April 26th 04 01:37 PM


All times are GMT +1. The time now is 08:48 AM.

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

About Us

"It's about Microsoft Excel"