Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel using code 2

Status
Not open for further replies.

darinmc

Technical User
Feb 27, 2005
171
GB
I have a spreadsheet, 1 column is name InvNo, I was wondering if there was code to automatically fill in the blanks..
Eg: Col appears like this...
1
2


3


4
5
Etc, I would like the number after 2, to be filled with 2's, then after 3, filled with 3's..
I know you can use the mouse and drag it, BUT my numbers run to around 170, the task is very VERY monotomous, boring and time consuming? :)
is this possible?

Thx
Darin
 
You've posted this in the Access Modules (VBA Coding) forum! You'll have a better chance with an answer reposting to the VBA: Visual Basic for Applications forum here!

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
My Excel VBA isn't very good so there may be a much better way of doing this but the following works:

Code:
Public Sub FillBlanks()
    Dim lngLastKnownVal As Long
    Dim pntr As Long
    Dim lngLastRow As Long
    
    For pntr = 1 To 65536
        If Sheet1.Cells(pntr, 1) <> "" Then lngLastRow = pntr
    Next pntr
        
    For pntr = 1 To lngLastRow
        If Sheet1.Cells(pntr, 1) <> "" Then
            lngLastKnownVal = Sheet1.Cells(pntr, 1)
        Else
            Sheet1.Cells(pntr, 1) = lngLastKnownVal
        End If
    Next pntr
End Sub

Ed Metcalfe.

Please do not feed the trolls.....
 
Thx, Never used VBA in excel, got it to work, EXCELLENT, thx Ed
 
You're welcome.

Ed Metcalfe.

Please do not feed the trolls.....
 



Hi,
Code:
Public Sub FillBlanks()
    Dim lngLastKnownVal As Long
    Dim pntr As Long
    Dim lngLastRow As Long
    
    [b]lngLastRow  = cells.find("*", cells(cells.rows.count,cells.columns.count) , , , xlByRows , xlPrevious).row[/b]
        
    For pntr = 1 To lngLastRow
        If Sheet1.Cells(pntr, 1) <> "" Then
            lngLastKnownVal = Sheet1.Cells(pntr, 1)
        Else
            Sheet1.Cells(pntr, 1) = lngLastKnownVal
        End If
    Next pntr
End Sub

Skip,

[glasses] [red][/red]
[tongue]
 
Yep, that was the bit I was thinking could be done better!

Ed Metcalfe.

Please do not feed the trolls.....
 
Thx To both.... even bettttttter lol

saves even more time...
Darin
 
darinmc . . .

If the help from [blue]Ed2020[/blue] & [blue]SkipVought[/blue] was that good, give them a star! [thumbsup2] . . . its the best way to show your appreciation and it signals other members of resolution!

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top