?
Solved

Cannot get macro to auto fill correct number of entries

Posted on 2016-08-19
10
Medium Priority
?
64 Views
Last Modified: 2016-08-19
Hi Experts using Excel 213

i have the following VBA code which to a certain extent works kind of fine....
I am trying to populate a formula is cell B8 down based on the number of entries in column B2 onwards sheet "Unique List" into B8 and fill down...
so if we have a count of 83 in B2:B85 then autofill said formula in cell B8 (inc B8) 83 times..

Sub Autopopulate()
    
    Dim Rng As Long, Rng1 As Range
    
    Application.ScreenUpdating = False
    
        Rng = Sheets("Unique List").Range("B" & Rows.Count).End(xlUp).Row ' the range of entries
            With Sheets("Broker Level")
        .Range("B8:B" & Rng).FillDown ' the range where the formula is in the first cell
    End With
    
    Application.ScreenUpdating = True

End Sub

Open in new window

0
Comment
Question by:route217
[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
  • 4
  • 3
  • 3
10 Comments
 
LVL 32

Assisted Solution

by:Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj) earned 1000 total points
ID: 41762290
Does this work for you?

Sub Autopopulate()
Dim Rng As Range
Application.ScreenUpdating = False
Set Rng = Range("B8:B" & Range("B2").Value)
Range("B8").AutoFill Rng, xlFillDefault
Application.ScreenUpdating = True
End Sub

Open in new window

0
 

Author Comment

by:route217
ID: 41762316
lets give it a try
0
 

Author Comment

by:route217
ID: 41762319
sorry no...

because as per original code b is in sheet unique and populate into worksheet Broker Level...hmm

appreciate the feedback
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:route217
ID: 41762350
ok i see where the error is.....but not sure how to correct it..

If you change to . Range("A2:A" & Rng).Filldown works fine.....
but my starting point is offset to B8...
0
 
LVL 32

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41762355
In that case qualify the Range("B2").Value with the sheet reference....

Like this...
Sheets("Unique").Range("B2").Value

Rng in your original code is a Long variable while Rng in the code I suggested it's a Range variable.
0
 
LVL 18

Accepted Solution

by:
xtermie earned 1000 total points
ID: 41762364
Try this
Sub Autopopulate2()
   
    Dim Rng As Long, Rng1 As Range
   
    Application.ScreenUpdating = False
   
        Rng = Sheets("Unique List").Range("B" & Rows.Count).End(xlUp).Row ' the range of entries
        Rng = Rng + 8
            With Sheets("Broker Level")
        .Range("B8:B" & Rng).FillDown ' the range where the formula is in the first cell
    End With
   
    Application.ScreenUpdating = True

End Sub
0
 
LVL 18

Expert Comment

by:xtermie
ID: 41762369
you are using the count of the Unique List as the ending part of the Range in the Broker level range
So for example if there are 83 entries in Unique list (Rng = 83) then your fill down area (range) in Broker Level is B8:B83 which is not what you want.

You want B8 +83 rows down, correct?
Which is B8:B91 (that's why I plus 8 your range)
0
 

Author Comment

by:route217
ID: 41762377
Thank u and thank u again..experts
1
 
LVL 32

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41762378
You're welcome..
0
 
LVL 18

Expert Comment

by:xtermie
ID: 41762379
glad we could help
0

Featured Post

Technology Partners: 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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
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…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

752 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