Solved

excel auto fill

Posted on 2014-04-08
10
286 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

910 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

18 Experts available now in Live!

Get 1:1 Help Now