Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Modify to write results into B2 down instead of msgbox

For the sub below, instead of msgbox, I would like to write
all results into say, B2 down on the sheet. How? Thanks.

Sub findmissingnumbersinlist()
mc = 1 'for col A
For i = 2 To Cells(Rows.Count, mc).End(xlUp).Row - 1
If Cells(i + 1, mc) < Cells(i, mc) + 1 Then
MsgBox "Missing " & Cells(i, mc) + 1 & " at row " & i + 1
End If
Next i
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Modify to write results into B2 down instead of msgbox

Hi,

I assume this does what you want because ity doesn't do what the sub name
implies i.e. find the mssing numbers in a series. It will work OK for 1
mising number but not 2 or more consecutive missing ones.

Howere this replicates the original code but now puts the missing numbers in
B2 down

Sub findmissingnumbersinlist()
mc = 1 'for col A
bc = 2 'column B
For i = 2 To Cells(Rows.Count, mc).End(xlUp).Row - 1
If Cells(i + 1, mc) < Cells(i, mc) + 1 Then
Cells(bc, 2).Value = Cells(i, mc) + 1
bc = bc + 1
End If
Next i
End Sub

Mike

"Max" wrote:

For the sub below, instead of msgbox, I would like to write
all results into say, B2 down on the sheet. How? Thanks.

Sub findmissingnumbersinlist()
mc = 1 'for col A
For i = 2 To Cells(Rows.Count, mc).End(xlUp).Row - 1
If Cells(i + 1, mc) < Cells(i, mc) + 1 Then
MsgBox "Missing " & Cells(i, mc) + 1 & " at row " & i + 1
End If
Next i
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Modify to write results into B2 down instead of msgbox

Hi,

If you want to list missing numbers where there are 2 or more consecutive
missing then try this modified version.

Sub findmissingnumbersinlist()
mc = 1 'for col A
bc = 2 'column B
y = 1
For i = 2 To Cells(Rows.Count, mc).End(xlUp).Row - 1
If Cells(i + 1, mc) < Cells(i, mc) + 1 Then
For x = Cells(i, mc) + 1 To Cells(i + 1, mc) - 1
Cells(bc, 2).Value = Cells(i, mc) + y
bc = bc + 1
y = y + 1
Next
y = 1
End If
Next i
End Sub

Mike

"Mike H" wrote:

Hi,

I assume this does what you want because ity doesn't do what the sub name
implies i.e. find the mssing numbers in a series. It will work OK for 1
mising number but not 2 or more consecutive missing ones.

Howere this replicates the original code but now puts the missing numbers in
B2 down

Sub findmissingnumbersinlist()
mc = 1 'for col A
bc = 2 'column B
For i = 2 To Cells(Rows.Count, mc).End(xlUp).Row - 1
If Cells(i + 1, mc) < Cells(i, mc) + 1 Then
Cells(bc, 2).Value = Cells(i, mc) + 1
bc = bc + 1
End If
Next i
End Sub

Mike

"Max" wrote:

For the sub below, instead of msgbox, I would like to write
all results into say, B2 down on the sheet. How? Thanks.

Sub findmissingnumbersinlist()
mc = 1 'for col A
For i = 2 To Cells(Rows.Count, mc).End(xlUp).Row - 1
If Cells(i + 1, mc) < Cells(i, mc) + 1 Then
MsgBox "Missing " & Cells(i, mc) + 1 & " at row " & i + 1
End If
Next i
End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Modify to write results into B2 down instead of msgbox

Many thanks, Mike, on both counts, the way to write to B2 down and the
intrinsic refinements. Runs fabulous.

Max


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Modify to write results into B2 down instead of msgbox

Since I authored the sub ( Thanks for the MISSING acknowledgment and
thanks ) I have sent you a file with one macro showing how to indicate the
missing and another macro inserting the missing.
Sub findmissingnumbersinlist()
mc = 1 'for col A
Columns(mc + 1).ClearContents
For i = 2 To Cells(Rows.Count, mc).End(xlUp).Row - 1
If Cells(i + 1, mc) < Cells(i, mc) + 1 Then
'MsgBox "Missing " & Cells(i, mc) + 1 & " at row " & i + 1
Cells(i + 1, mc + 1) = Cells(i, mc) + 1
End If
Next i
End Sub
Sub insertmissing()
mc = 1 'for col A
For i = 2 To Cells(Rows.Count, mc).End(xlUp).Row - 1
If Cells(i + 1, mc) < Cells(i, mc) + 1 Then
Rows(i + 1).Insert
Cells(i + 1, mc) = Cells(i, mc) + 1
End If
Next i
End Sub
--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Max" wrote in message
...
For the sub below, instead of msgbox, I would like to write
all results into say, B2 down on the sheet. How? Thanks.

Sub findmissingnumbersinlist()
mc = 1 'for col A
For i = 2 To Cells(Rows.Count, mc).End(xlUp).Row - 1
If Cells(i + 1, mc) < Cells(i, mc) + 1 Then
MsgBox "Missing " & Cells(i, mc) + 1 & " at row " & i + 1
End If
Next i
End Sub




  #6   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Modify to write results into B2 down instead of msgbox

Don,

My apologies for missing out the sub's authorship acknowledgement earlier. I
haven't received anything in my yahoo email, if you have sent me something.

Since we are on the line here,
I have one request for your GetWorkbook sub,
re this thread: http://tinyurl.com/9beyhs
Appreciate your response

Max


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Modify to write results into B2 down instead of msgbox

I apologize. I thought you were the same poster that I originally sent it
to. If you want the workbook ,ask me off line. Here is the getworkbook macro
that works from the other based on the name of the workbook typed into the
cell.
Sub GetWorkbook()
If ActiveCell.Value = "" Then Exit Sub
workbookname = ActiveCell.Value
On Error GoTo OpenWorkbook
Windows(workbookname & ".xls").Activate
Exit Sub
OpenWorkbook:
Workbooks.Open(workbookname & ".xls").RunAutoMacros xlAutoOpen
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Max" wrote in message
...
Don,

My apologies for missing out the sub's authorship acknowledgement earlier.
I haven't received anything in my yahoo email, if you have sent me
something.

Since we are on the line here,
I have one request for your GetWorkbook sub,
re this thread:
http://tinyurl.com/9beyhs
Appreciate your response

Max


  #8   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Modify to write results into B2 down instead of msgbox

Don,

No prob. Many thanks for your Sub GetWorkbook().

Max


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
How to write a macro to modify an Excel chart raymondvillain Charts and Charting in Excel 4 July 14th 07 04:38 PM
Wanting to write results to array instead of sheet, results overwriting.... [email protected] Excel Programming 2 October 31st 05 01:47 PM
Showing Search results in msgbox? Ed[_9_] Excel Programming 1 August 28th 03 05:13 PM


All times are GMT +1. The time now is 07:35 PM.

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"