PC Review


Reply
Thread Tools Rate Thread

Add missing numbers in a sequence

 
 
jack
Guest
Posts: n/a
 
      18th Oct 2009
I have data (example as shown below) that exports from a database in excel
file format on a daily basis.
What I need to do is insert the missing sequential numbers (starting with
001 and ending with 150) in each cell in column A and add a value of zero
for the missing sequential numbers in column B.
I'm at a loss as how to do this!
How I can accomplish with VBA (or another method) ?
Thanks..
Jack

A B
004 67
005 11
006 30
007 14
008 3
009 2
010 1
011 9
014 5
015 12
016 1
018 73
021 28
022 4
024 2
025 1
026 3
027 23
033 1
035 2
036 1
038 12
040 1
044 5
047 1
051 31
052 5
055 1
056 3
057 2
060 26
066 1
067 1
072 14
073 6
080 6
081 2
082 41
088 8
089 1
091 28
092 1
102 1
103 1
104 1
118 2


 
Reply With Quote
 
 
 
 
Tim Williams
Guest
Posts: n/a
 
      18th Oct 2009
Try this:


'************************************
Sub tester()
Dim x As Long, val As String
Dim rngFind As Range

With ActiveSheet
Set rngFind = .Range(.Range("A2"), _
.Range("A2").End(xlDown))

End With

For x = 1 To 150
val = Right("000" & x, 3)
If rngFind.Find(val, , xlValues, xlWhole) Is Nothing Then
With ActiveSheet.Range("A2").End(xlDown).Offset(1, 0)
.NumberFormat = "@"
.Value = val
.Offset(0, 1).Value = 0
End With
End If
Next x

End Sub
'**********************************

Tim



"jack" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have data (example as shown below) that exports from a database in excel
> file format on a daily basis.
> What I need to do is insert the missing sequential numbers (starting with
> 001 and ending with 150) in each cell in column A and add a value of zero
> for the missing sequential numbers in column B.
> I'm at a loss as how to do this!
> How I can accomplish with VBA (or another method) ?
> Thanks..
> Jack
>
> A B
> 004 67
> 005 11
> 006 30
> 007 14
> 008 3
> 009 2
> 010 1
> 011 9
> 014 5
> 015 12
> 016 1
> 018 73
> 021 28
> 022 4
> 024 2
> 025 1
> 026 3
> 027 23
> 033 1
> 035 2
> 036 1
> 038 12
> 040 1
> 044 5
> 047 1
> 051 31
> 052 5
> 055 1
> 056 3
> 057 2
> 060 26
> 066 1
> 067 1
> 072 14
> 073 6
> 080 6
> 081 2
> 082 41
> 088 8
> 089 1
> 091 28
> 092 1
> 102 1
> 103 1
> 104 1
> 118 2
>
>



 
Reply With Quote
 
Per Jessen
Guest
Posts: n/a
 
      18th Oct 2009
Hi Jack

Try this:

Sub aaa()
'Dim myArr
Dim rng As Range
Set rng = Range("A1", Range("B1").End(xlDown))
myArr = Array(rng.Value)
rCount = Range("A1").End(xlDown).Row
Range("A1") = 1
Range("A2") = 2
Range("A1:A2").Select
Selection.AutoFill Destination:=Range("A1:A150"), Type:=xlFillDefault
Range("B1:B150") = 0
For r = 1 To rCount
Cells(myArr(0)(r, 1), 2) = myArr(arr)(r, 2)
Next
Columns("A").NumberFormat = "###000"
End Sub

Regards,
Per

"jack" <(E-Mail Removed)> skrev i meddelelsen
news:(E-Mail Removed)...
>I have data (example as shown below) that exports from a database in excel
> file format on a daily basis.
> What I need to do is insert the missing sequential numbers (starting with
> 001 and ending with 150) in each cell in column A and add a value of zero
> for the missing sequential numbers in column B.
> I'm at a loss as how to do this!
> How I can accomplish with VBA (or another method) ?
> Thanks..
> Jack
>
> A B
> 004 67
> 005 11
> 006 30
> 007 14
> 008 3
> 009 2
> 010 1
> 011 9
> 014 5
> 015 12
> 016 1
> 018 73
> 021 28
> 022 4
> 024 2
> 025 1
> 026 3
> 027 23
> 033 1
> 035 2
> 036 1
> 038 12
> 040 1
> 044 5
> 047 1
> 051 31
> 052 5
> 055 1
> 056 3
> 057 2
> 060 26
> 066 1
> 067 1
> 072 14
> 073 6
> 080 6
> 081 2
> 082 41
> 088 8
> 089 1
> 091 28
> 092 1
> 102 1
> 103 1
> 104 1
> 118 2
>
>


 
Reply With Quote
 
jack
Guest
Posts: n/a
 
      23rd Oct 2009
I'm having a difficult time with issue.
The database output has changed in two different ways:
1)The event output (column A) for each row is now preceeded with a "C-"
followed by a number or a "CC-" followed by a number.
2)There two different groups of events with event numbers (column A)
repeating and different quantities for the repeating groups.

As in the original post, I need to do is insert the missing sequential
numbers (starting with C-001 and ending with C-150 also CC-001 and ending
with CC-030) in each cell in column A and add a value of zero
for the missing sequential numbers in column B. In addition, I need to add
together the values of the repeating events. The result to be a listing of
events and values (added together where required for duplicate event
numbers) with a value of zero for those missing event numbers.
Any help will be greatly appreciated!!!
Sample data follows.
Thanks.....
Jack

Group A
A B
C - 003 153
C - 004 45
C - 005 2
C - 006 18
C - 008 9
C - 009 4
C - 010 2
C - 011 1
C - 013 3
C - 014 1
C - 015 1
C - 016 1
C - 017 1
C - 021 17
C - 022 1
C - 026 9
C - 028 1
C - 030 19
C - 031 7
C - 034 1
C - 039 1
C - 047 3
C - 048 9
C - 049 6
C - 051 3
C - 058 2
C - 064 8
C - 065 1
C - 110 17
C - 111 1
C - 112 18
C - 114 1
C - 117 1
C - 119 5
C - 120 1
C - 134 1
C - 135 1
CC - 003 5
CC - 004 3
CC - 011 3
group B
C - 003 1
C - 008 1
C - 009 1
C - 021 2
C - 051 2
C - 111 1
"jack" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
I have data (example as shown below) that exports from a database in excel
file format on a daily basis.
What I need to do is insert the missing sequential numbers (starting with
001 and ending with 150) in each cell in column A and add a value of zero
for the missing sequential numbers in column B.
I'm at a loss as how to do this!
How I can accomplish with VBA (or another method) ?
Thanks..
Jack

A B
004 67
005 11
006 30
007 14
008 3
009 2
010 1
011 9
014 5
015 12
016 1
018 73
021 28
022 4
024 2
025 1
026 3
027 23
033 1
035 2
036 1
038 12
040 1
044 5
047 1
051 31
052 5
055 1
056 3
057 2
060 26
066 1
067 1
072 14
073 6
080 6
081 2
082 41
088 8
089 1
091 28
092 1
102 1
103 1
104 1
118 2



 
Reply With Quote
 
Tim Williams
Guest
Posts: n/a
 
      23rd Oct 2009
Sub Tester()
Dim oDict As Object
Dim c As Range, v, k, x As Integer

Set oDict = CreateObject("scripting.dictionary")

For Each c In ActiveSheet.Range("A2:A400")
v = Trim(c.Value)
If (v Like "C - *") Or (v Like "CC - *") Then
If oDict.exists(v) Then
oDict(v) = oDict(v) + c.Offset(0, 1).Value
Else
oDict.Add v, c.Offset(0, 1).Value
End If
End If
Next c

Set c = ActiveSheet.Range("E2") 'or wherever...
For x = 1 To 150
v = "C - " & Right("00" & x, 3)
c.Value = v
c.Offset(0, 1).Value = IIf(oDict.exists(v), oDict(v), 0)
Set c = c.Offset(1, 0)
Next x
For x = 1 To 150
v = "CC - " & Right("00" & x, 3)
c.Value = v
c.Offset(0, 1).Value = IIf(oDict.exists(v), oDict(v), 0)
Set c = c.Offset(1, 0)
Next x

End Sub


Tim

"jack" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm having a difficult time with issue.
> The database output has changed in two different ways:
> 1)The event output (column A) for each row is now preceeded with a "C-"
> followed by a number or a "CC-" followed by a number.
> 2)There two different groups of events with event numbers (column A)
> repeating and different quantities for the repeating groups.
>
> As in the original post, I need to do is insert the missing sequential
> numbers (starting with C-001 and ending with C-150 also CC-001 and ending
> with CC-030) in each cell in column A and add a value of zero
> for the missing sequential numbers in column B. In addition, I need to add
> together the values of the repeating events. The result to be a listing of
> events and values (added together where required for duplicate event
> numbers) with a value of zero for those missing event numbers.
> Any help will be greatly appreciated!!!
> Sample data follows.
> Thanks.....
> Jack
>
> Group A
> A B
> C - 003 153
> C - 004 45
> C - 005 2
> C - 006 18
> C - 008 9
> C - 009 4
> C - 010 2
> C - 011 1
> C - 013 3
> C - 014 1
> C - 015 1
> C - 016 1
> C - 017 1
> C - 021 17
> C - 022 1
> C - 026 9
> C - 028 1
> C - 030 19
> C - 031 7
> C - 034 1
> C - 039 1
> C - 047 3
> C - 048 9
> C - 049 6
> C - 051 3
> C - 058 2
> C - 064 8
> C - 065 1
> C - 110 17
> C - 111 1
> C - 112 18
> C - 114 1
> C - 117 1
> C - 119 5
> C - 120 1
> C - 134 1
> C - 135 1
> CC - 003 5
> CC - 004 3
> CC - 011 3
> group B
> C - 003 1
> C - 008 1
> C - 009 1
> C - 021 2
> C - 051 2
> C - 111 1
> "jack" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> I have data (example as shown below) that exports from a database in excel
> file format on a daily basis.
> What I need to do is insert the missing sequential numbers (starting with
> 001 and ending with 150) in each cell in column A and add a value of zero
> for the missing sequential numbers in column B.
> I'm at a loss as how to do this!
> How I can accomplish with VBA (or another method) ?
> Thanks..
> Jack
>
> A B
> 004 67
> 005 11
> 006 30
> 007 14
> 008 3
> 009 2
> 010 1
> 011 9
> 014 5
> 015 12
> 016 1
> 018 73
> 021 28
> 022 4
> 024 2
> 025 1
> 026 3
> 027 23
> 033 1
> 035 2
> 036 1
> 038 12
> 040 1
> 044 5
> 047 1
> 051 31
> 052 5
> 055 1
> 056 3
> 057 2
> 060 26
> 066 1
> 067 1
> 072 14
> 073 6
> 080 6
> 081 2
> 082 41
> 088 8
> 089 1
> 091 28
> 092 1
> 102 1
> 103 1
> 104 1
> 118 2
>
>
>



 
Reply With Quote
 
jack
Guest
Posts: n/a
 
      23rd Oct 2009
Thanks Tim,
I'll give a try later on today.
Jack

"Tim Williams" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
Sub Tester()
Dim oDict As Object
Dim c As Range, v, k, x As Integer

Set oDict = CreateObject("scripting.dictionary")

For Each c In ActiveSheet.Range("A2:A400")
v = Trim(c.Value)
If (v Like "C - *") Or (v Like "CC - *") Then
If oDict.exists(v) Then
oDict(v) = oDict(v) + c.Offset(0, 1).Value
Else
oDict.Add v, c.Offset(0, 1).Value
End If
End If
Next c

Set c = ActiveSheet.Range("E2") 'or wherever...
For x = 1 To 150
v = "C - " & Right("00" & x, 3)
c.Value = v
c.Offset(0, 1).Value = IIf(oDict.exists(v), oDict(v), 0)
Set c = c.Offset(1, 0)
Next x
For x = 1 To 150
v = "CC - " & Right("00" & x, 3)
c.Value = v
c.Offset(0, 1).Value = IIf(oDict.exists(v), oDict(v), 0)
Set c = c.Offset(1, 0)
Next x

End Sub


Tim

"jack" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm having a difficult time with issue.
> The database output has changed in two different ways:
> 1)The event output (column A) for each row is now preceeded with a "C-"
> followed by a number or a "CC-" followed by a number.
> 2)There two different groups of events with event numbers (column A)
> repeating and different quantities for the repeating groups.
>
> As in the original post, I need to do is insert the missing sequential
> numbers (starting with C-001 and ending with C-150 also CC-001 and ending
> with CC-030) in each cell in column A and add a value of zero
> for the missing sequential numbers in column B. In addition, I need to add
> together the values of the repeating events. The result to be a listing of
> events and values (added together where required for duplicate event
> numbers) with a value of zero for those missing event numbers.
> Any help will be greatly appreciated!!!
> Sample data follows.
> Thanks.....
> Jack
>
> Group A
> A B
> C - 003 153
> C - 004 45
> C - 005 2
> C - 006 18
> C - 008 9
> C - 009 4
> C - 010 2
> C - 011 1
> C - 013 3
> C - 014 1
> C - 015 1
> C - 016 1
> C - 017 1
> C - 021 17
> C - 022 1
> C - 026 9
> C - 028 1
> C - 030 19
> C - 031 7
> C - 034 1
> C - 039 1
> C - 047 3
> C - 048 9
> C - 049 6
> C - 051 3
> C - 058 2
> C - 064 8
> C - 065 1
> C - 110 17
> C - 111 1
> C - 112 18
> C - 114 1
> C - 117 1
> C - 119 5
> C - 120 1
> C - 134 1
> C - 135 1
> CC - 003 5
> CC - 004 3
> CC - 011 3
> group B
> C - 003 1
> C - 008 1
> C - 009 1
> C - 021 2
> C - 051 2
> C - 111 1
> "jack" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> I have data (example as shown below) that exports from a database in excel
> file format on a daily basis.
> What I need to do is insert the missing sequential numbers (starting with
> 001 and ending with 150) in each cell in column A and add a value of zero
> for the missing sequential numbers in column B.
> I'm at a loss as how to do this!
> How I can accomplish with VBA (or another method) ?
> Thanks..
> Jack
>
> A B
> 004 67
> 005 11
> 006 30
> 007 14
> 008 3
> 009 2
> 010 1
> 011 9
> 014 5
> 015 12
> 016 1
> 018 73
> 021 28
> 022 4
> 024 2
> 025 1
> 026 3
> 027 23
> 033 1
> 035 2
> 036 1
> 038 12
> 040 1
> 044 5
> 047 1
> 051 31
> 052 5
> 055 1
> 056 3
> 057 2
> 060 26
> 066 1
> 067 1
> 072 14
> 073 6
> 080 6
> 081 2
> 082 41
> 088 8
> 089 1
> 091 28
> 092 1
> 102 1
> 103 1
> 104 1
> 118 2
>
>
>




 
Reply With Quote
 
jack
Guest
Posts: n/a
 
      24th Oct 2009
Thanks Tim,
The code worked great!!
Jack

"Tim Williams" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
Sub Tester()
Dim oDict As Object
Dim c As Range, v, k, x As Integer

Set oDict = CreateObject("scripting.dictionary")

For Each c In ActiveSheet.Range("A2:A400")
v = Trim(c.Value)
If (v Like "C - *") Or (v Like "CC - *") Then
If oDict.exists(v) Then
oDict(v) = oDict(v) + c.Offset(0, 1).Value
Else
oDict.Add v, c.Offset(0, 1).Value
End If
End If
Next c

Set c = ActiveSheet.Range("E2") 'or wherever...
For x = 1 To 150
v = "C - " & Right("00" & x, 3)
c.Value = v
c.Offset(0, 1).Value = IIf(oDict.exists(v), oDict(v), 0)
Set c = c.Offset(1, 0)
Next x
For x = 1 To 150
v = "CC - " & Right("00" & x, 3)
c.Value = v
c.Offset(0, 1).Value = IIf(oDict.exists(v), oDict(v), 0)
Set c = c.Offset(1, 0)
Next x

End Sub


Tim

"jack" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm having a difficult time with issue.
> The database output has changed in two different ways:
> 1)The event output (column A) for each row is now preceeded with a "C-"
> followed by a number or a "CC-" followed by a number.
> 2)There two different groups of events with event numbers (column A)
> repeating and different quantities for the repeating groups.
>
> As in the original post, I need to do is insert the missing sequential
> numbers (starting with C-001 and ending with C-150 also CC-001 and ending
> with CC-030) in each cell in column A and add a value of zero
> for the missing sequential numbers in column B. In addition, I need to add
> together the values of the repeating events. The result to be a listing of
> events and values (added together where required for duplicate event
> numbers) with a value of zero for those missing event numbers.
> Any help will be greatly appreciated!!!
> Sample data follows.
> Thanks.....
> Jack
>
> Group A
> A B
> C - 003 153
> C - 004 45
> C - 005 2
> C - 006 18
> C - 008 9
> C - 009 4
> C - 010 2
> C - 011 1
> C - 013 3
> C - 014 1
> C - 015 1
> C - 016 1
> C - 017 1
> C - 021 17
> C - 022 1
> C - 026 9
> C - 028 1
> C - 030 19
> C - 031 7
> C - 034 1
> C - 039 1
> C - 047 3
> C - 048 9
> C - 049 6
> C - 051 3
> C - 058 2
> C - 064 8
> C - 065 1
> C - 110 17
> C - 111 1
> C - 112 18
> C - 114 1
> C - 117 1
> C - 119 5
> C - 120 1
> C - 134 1
> C - 135 1
> CC - 003 5
> CC - 004 3
> CC - 011 3
> group B
> C - 003 1
> C - 008 1
> C - 009 1
> C - 021 2
> C - 051 2
> C - 111 1
> "jack" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> I have data (example as shown below) that exports from a database in excel
> file format on a daily basis.
> What I need to do is insert the missing sequential numbers (starting with
> 001 and ending with 150) in each cell in column A and add a value of zero
> for the missing sequential numbers in column B.
> I'm at a loss as how to do this!
> How I can accomplish with VBA (or another method) ?
> Thanks..
> Jack
>
> A B
> 004 67
> 005 11
> 006 30
> 007 14
> 008 3
> 009 2
> 010 1
> 011 9
> 014 5
> 015 12
> 016 1
> 018 73
> 021 28
> 022 4
> 024 2
> 025 1
> 026 3
> 027 23
> 033 1
> 035 2
> 036 1
> 038 12
> 040 1
> 044 5
> 047 1
> 051 31
> 052 5
> 055 1
> 056 3
> 057 2
> 060 26
> 066 1
> 067 1
> 072 14
> 073 6
> 080 6
> 081 2
> 082 41
> 088 8
> 089 1
> 091 28
> 092 1
> 102 1
> 103 1
> 104 1
> 118 2
>
>
>




 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Display missing numbers from a sequence lrxc Microsoft Excel Programming 1 2nd Nov 2009 11:35 PM
Find Missing Numbers in a Sequence Gary Dolliver Microsoft Access Queries 3 20th Dec 2007 01:31 PM
find missing sequence of numbers =?Utf-8?B?Ym9va3dvcm0=?= Microsoft Access 4 21st Oct 2005 06:23 AM
Finding numbers missing from a sequence andy Microsoft Excel Misc 3 8th Apr 2005 04:16 PM
Displaying Numbers Missing In A Sequence Rick D Microsoft Excel Worksheet Functions 7 25th Nov 2003 07:32 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:58 PM.