Solved

excel auto fill

Posted on 2014-04-08
10
289 Views
Last Modified: 2014-04-08
I need to be able to work down the rows in the attached spreadsheet to do the following:

Column D has a number of text names
Column B has numbers associated with these names
bill always associates withy 123
john always associates with 456
etc .......
jill does not have an association

and so on

Problem:
sometimes there are gaps in the B column such that the correct associated number has not
been filled in

I need to be able to automate this process so that all gaps are filled in with the appropriate number
The number of rows could go into thousands

Thoughts please
example.xls
0
Comment
Question by:doctorbill
  • 5
  • 4
10 Comments
 
LVL 50

Expert Comment

by:Rgonzo1971
ID: 39985882
Hi,

pls try

Sub macro()
For Each c In Range("B:B").SpecialCells(xlCellTypeBlanks)
    If c.Offset(-1, 2) = c.Offset(0, 2) Then
        c.Value = c.Offset(-1, 0).Value
    End If
Next
End Sub

Open in new window

Regards
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 39985906
This works for the given scenario

Without code:

Select the column B range. In this case it is B2:B37
press F5
Click on special
Select blanks
Click OK
type   =
from the keyboard move the cursor one cell up
press ctrl-enter

With code

Sub fillwithuppercells()
ActiveSheet.UsedRange.Columns(2).SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=r[-1]c"
End Sub
0
 

Author Comment

by:doctorbill
ID: 39986149
Re this formula:

Sub macro()
For Each c In Range("B:B").SpecialCells(xlCellTypeBlanks)
    If c.Offset(-1, 2) = c.Offset(0, 2) Then
        c.Value = c.Offset(-1, 0).Value
    End If
Next
End Sub

Sorry - my mistake. The numerical values should be in column C and the text names in Column E
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 50

Expert Comment

by:Rgonzo1971
ID: 39986167
HI

then

Sub macro()
For Each c In Range("C:C").SpecialCells(xlCellTypeBlanks)
    If c.Offset(-1, 2) = c.Offset(0, 2) Then
        c.Value = c.Offset(-1, 0).Value
    End If
Next
End Sub

Open in new window

Regards
0
 

Author Comment

by:doctorbill
ID: 39986216
When I try to run it I get the following error:

400

any ideas ?
0
 
LVL 50

Expert Comment

by:Rgonzo1971
ID: 39986233
Where does the code stop?
0
 

Author Comment

by:doctorbill
ID: 39986260
This is the file which does not work - it has your code in it
newtest.xls
0
 
LVL 50

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39986296
HI,

try this

Sub macro()
For Each c In Range(Range("C2"), Range("E" & Cells.Rows.Count).End(xlUp).Offset(0, -2))
    If c.Offset(-1, 2) = c.Offset(0, 2) Then
        c.Value = c.Offset(-1, 0).Value
    End If
Next
End Sub

Open in new window

Regards
0
 

Author Comment

by:doctorbill
ID: 39986365
Perfect - thanks very much
0
 

Author Closing Comment

by:doctorbill
ID: 39986371
solved
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question