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
Solved

Cannot get macro to auto fill correct number of entries

Posted on 2016-08-19
10
60 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
  • 4
  • 3
  • 3
10 Comments
 
LVL 30

Assisted Solution

by:Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj) earned 250 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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 30

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 250 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 30

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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 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…
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…

809 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