Solved

excel auto fill

Posted on 2014-04-08
10
287 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 49

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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 49

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 49

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 49

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
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…

815 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now