Solved

excel auto fill

Posted on 2014-04-08
10
296 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
[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
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 52

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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 52

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 52

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 52

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

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!

Question has a verified solution.

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

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.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

636 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