Solved

Cannot get macro to auto fill correct number of entries

Posted on 2016-08-19
10
57 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 29

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
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

 

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 29

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 29

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

773 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