Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7783751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:55:49+00:00 2026-06-01T19:55:49+00:00

I have a range of data, from a vba prompt held in a type

  • 0

I have a range of data, from a vba prompt held in a type range variable. I am trying to then go through this range, and for each empty cell, replace it with the average of it’s column.

I can replace the empty cells fine, but it’s getting the average of each column I am strugging with. Is there an easy way?

I prefer not to do a loop for each column, a loop for each row and then calculate it using total/numberOfNonEmptyCells as this takes a fair bit of time ( And i’m evidently doing something wrong here as i’m getting the wrong value )… but i’m sure it’s not the only or correct way to do it.

Is there any kind of way of saying:

For Each Column
Get column i from the range
Get the average of that column.
Put it in an array.

Then have a loop going through replacing the empty cells with that value?

OR, even better a way of just putting in a formula into the empty cells saying
= AVERAGE(Column from Range)
I tried this using AVERAGE(Range.Columns,1) and it didn’t work, as it is of type Column I believe which average won’t work with.

The easiest way to do this I will mark as the answer. It needs to use a macro though rather than just being manually putting the formula in, as it’s for a lot of data on a lot of sheets.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T19:55:50+00:00Added an answer on June 1, 2026 at 7:55 pm

    This will a selected range, per column, filling in blank cells with the average on non-blank cells.

    It addresses your speed concern, by minimising access to cells in the loops (tested on about 5,000,000 cells, took about 10s) (could possibly be improved further at the expence of more complex code)

    Preserves any formulas

    Sub FillInAverage()
        Dim rng As Range
        Dim col As Range
        Dim a As Variant
        Dim dat As Variant
        Dim i As Long
    
        Set rng = Selection
        For Each col In rng.Columns
            a = Application.WorksheetFunction.Average(col)
            dat = col.Formula
            For i = 1 To UBound(dat, 1)
                If Len(dat(i, 1)) = 0 Then
                    dat(i, 1) = a
                End If
            Next
            col.Formula = dat
        Next
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code which retrieves some data from a sql query and place
Say I have a range of data from A1:Y55 containg data like 123 UID
I have a range of data that I have approximated using a polynomial of
I have a GUI Java code for calculating the range of data for example
I have a range named STATE. I want to set data validation in range
I have a column of data that contains a percentage range as a string
I have range of numbers that range from 1 - 0.00000X . Most are
Suppose I have range from E2 to E16. How do I read values from
I have a Range variable that contains an address - $2:$2,$4:$205,$214:$214 - (3 groups
I have the following vba: Data is all text, Rows A - J with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.