how do i get excel to add 0s???

CThai

Active Member
Joined
Mar 18, 2007
Messages
295
i have a workbook with missing dates and would like excel to insert any missing dates and add 0's into that missing dates if there is no data...

for example
Book1
ABCD
1DateCompany NameTotal
21/2/2006A25
31/2/2006A35
41/3/2006B125
51/5/2006B20
61/5/2006B185
71/7/2006A200
81/8/2006B250
91/10/2006B250
101/10/2006A350
Sheet1
 
hi QuietRiot -

Your codes work great ! just one minor thing in the part where it say company's name - it's showing up "Y" and "D" is there away i can have it to show up as the company's name --- since in column C i have it 37368A - can it just show up A in column B when run the codes?

thank you
 
Upvote 0

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
can you post some samples of your real data

so i can get a better idea
 
Upvote 0
PADD_testDaily.xls
ABCD
24/22/2002Giant37368Giant9875
34/22/2002Giant37368Giant9875
44/22/2002y37368Valero0
54/22/2002y37368Valero0
64/23/2002Giant37369Giant15000
74/23/2002y37369Valero0
84/24/2002Giant37370Giant15000
94/24/2002y37370Valero0
104/25/2002Giant37371Giant15000
114/25/2002y37371Valero0
1210/20/2002Valero37549Valero11500
1310/20/2002d37549Giant0
1410/21/2002Valero37550Valero11500
1510/21/2002d37550Giant0
1610/24/2002Valero37553Valero27500
1710/24/2002d37553Giant0
1810/25/2002Valero37554Valero27500
1910/25/2002d37554Giant0
Coker
 
Upvote 0
so what are the actual companies

i programmed it for just A and B

will it always be giant and valero?
 
Upvote 0
try this

Code:
Sub addzeros()
Dim rng As String, llast As String, g As Long


Set c = Cells.Find(What:="*", After:=[A1], SearchDirection:=xlPrevious)
If c Is Nothing Then
    last = 1
Else
    last = c.Row
End If
llast = last
rng = "C2:C" + llast
a = last + 1

For x = 2 To last
datte = Cells(x, 3).Value
  checkdatte = Left(datte, 5) + "Giant"
    g = Application.WorksheetFunction.CountIf(Range(rng), checkdatte)
If g < 1 Then
Cells(a, 3).Formula = checkdatte
Cells(a, 4).Formula = 0
Cells(a, 2).Formula = Mid(checkdatte, 6, 20)
Cells(a, 1).Formula = Left(checkdatte, 5)
a = a + 1
Else
End If
Next x
  
For x = 2 To last
datte = Cells(x, 3).Value
  checkdatte = Left(datte, 5) + "Valero"
    g = Application.WorksheetFunction.CountIf(Range(rng), checkdatte)
If g < 1 Then
Cells(a, 3).Formula = checkdatte
Cells(a, 4).Formula = 0
Cells(a, 2).Formula = Mid(checkdatte, 6, 20)
Cells(a, 1).Formula = Left(checkdatte, 5)
a = a + 1
Else
End If
Next x
    
Columns("A:A").Select
    Selection.NumberFormat = "m/d/yyyy"

End Sub
 
Upvote 0
will it always be giant and valero?

No the company will not alway be Gaint and Valero --- I'm using your codes for multiple worksheets with multiple company's names... some worksheets will have more then 2 company's listed -

I have to tell you I was so happy yesterday when i ran your codes I wanted to reach and give you the biggest hugs :)
 
Upvote 0
haha,
I think we might have to toss it though


i'll see what i can come up with
 
Upvote 0
can you post one more sample data without running the code
 
Upvote 0
without the codes ---
Book2
ABCD
220-Oct-02Valero2300023000
321-Oct-02Valero2300023000
424-Oct-02Valero5500055000
525-Oct-02Valero5500055000
626-Oct-02Valero5500055000
727-Oct-02Valero5500055000
828-Oct-02Valero5500055000
929-Oct-02Valero5500055000
1030-Oct-02Valero5500055000
1131-Oct-02Valero5500055000
1229-Nov-02Valero5500055000
1330-Nov-02Valero5500055000
141-Dec-02Valero5500055000
1522-Apr-02Giant3000019750
1622-Apr-02Giant950019750
1723-Apr-02Giant3000030000
1824-Apr-02Giant3000030000
1925-Apr-02Giant3000030000
2021-Mar-03Giant5300036250
2121-Mar-03Giant1950036250
2222-Mar-03Giant5300036250
2322-Mar-03Giant1950036250
2423-Mar-03Giant5300036250
2523-Mar-03Giant1950036250
2624-Mar-03Giant5300036250
Coker
 
Upvote 0
how does this work for you?

Code:
Sub addzeros()
Dim rng As String, llast As String, g As Long, strname As String

Set c = Cells.Find(What:="*", After:=[A1], SearchDirection:=xlPrevious)
If c Is Nothing Then
    last = 1
Else
    last = c.Row
End If
llast = last
rng = "C2:C" + llast
a = last + 1

strname = InputBox(Prompt:="Company Name to add zeros", _
          Title:="ENTER COMPANY NAME")

For x = 2 To last
datte = Cells(x, 3).Value
  checkdatte = Left(datte, 5) + strname
    g = Application.WorksheetFunction.CountIf(Range(rng), checkdatte)
If g < 1 Then
Cells(a, 3).Formula = checkdatte
Cells(a, 4).Formula = 0
Cells(a, 2).Formula = Mid(checkdatte, 6, 20)
Cells(a, 1).Formula = Left(checkdatte, 5)
a = a + 1
Else
End If
Next x
  
Columns("A:A").Select
    Selection.NumberFormat = "m/d/yyyy"

End Sub

just run it for every company by entering the company name.
 
Upvote 0

Forum statistics

Threads
1,214,975
Messages
6,122,538
Members
449,088
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top