Solved

Cannot get macro to auto fill correct number of entries

Posted on 2016-08-19
10
45 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 28

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
 

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 28

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 17

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 17

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 28

Expert Comment

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

Expert Comment

by:xtermie
ID: 41762379
glad we could help
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

708 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

16 Experts available now in Live!

Get 1:1 Help Now