Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

excel auto fill

Posted on 2014-04-08
Medium Priority
297 Views
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

example.xls
0
Question by:doctorbill
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 5
• 4

LVL 52

Expert Comment

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
``````
Regards
0

LVL 43

Expert Comment

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

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

LVL 52

Expert Comment

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
``````
Regards
0

Author Comment

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

400

any ideas ?
0

LVL 52

Expert Comment

ID: 39986233
Where does the code stop?
0

Author Comment

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

LVL 52

Accepted Solution

Rgonzo1971 earned 2000 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
``````
Regards
0

Author Comment

ID: 39986365
Perfect - thanks very much
0

Author Closing Comment

ID: 39986371
solved
0

Featured Post

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference texâ€¦
Excel can be a tricky bit of software to get your head around. Whilst youâ€™ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to dâ€¦
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calculâ€¦
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Suggested Courses
Course of the Month6 days, 7 hours left to enroll