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 8262891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:54:35+00:00 2026-06-08T03:54:35+00:00

I am trying to get a simple VBA code as part of a Macro

  • 0

I am trying to get a simple VBA code as part of a Macro that will put in column B the average of the values for each row.
I have code that generates a time series and fills a column per simulation such that each column is a time series starting at column C.
The number of simulations vary so I simply need something that averages the value for each point in time (ie for each row across all simulations) whilst adjusting for the number of simulations that are run (columns that are filled). I would then like it to generate a single graph of all the time series highlighting the average values that are calculated.
Many thanks if you can help!

Here, for example, is the code that takes the values for the time steps from sheet1 and places it in columnA sheet2. I would like the macro to now place the average in the appropriate row down Column B:
Screenshot Of current output

Sheets("Sheet1").Select
Range("E5").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets("Sheet2").Select
Cells(1, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
  • 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-08T03:54:37+00:00Added an answer on June 8, 2026 at 3:54 am

    Try this

    Sub Sample()
        Dim ws As Worksheet
        Dim lRow As Long
    
        Set ws = Sheets("Sheet1")
    
        With ws
            lRow = .Range("A" & .Rows.Count).End(xlUp).Row
    
            .Range("B2:B" & lRow).Formula = _
            "=IF(ISERROR(AVERAGE(C2:E2)),"""",AVERAGE(C2:E2))"
        End With
    End Sub
    

    FOLLOWUP

    Try this

    Sub Sample()
        Dim ws As Worksheet
        Dim lRow As Long, lCol As Long
        Dim ColNm As String
    
        Set ws = Sheets("Sheet1")
    
        With ws
            lRow = .Range("A" & .Rows.Count).End(xlUp).Row
            lCol = .Cells(2, .Columns.Count).End(xlToLeft).Column
            ColNm = Split(.Cells(, lCol).Address, "$")(1)
    
            .Range("B2:B" & lRow).Formula = "=IF(ISERROR(AVERAGE(C2:" _
                                            & ColNm & _
                                            "2)),"""",AVERAGE(C2:" & _
                                            ColNm & "2))"
        End With
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get a simple page up that will have four links
I am trying to get a simple demo started with ActiveMQ that will demonstrate
I'm trying to get simple code working, unfortunately I'm a python beginner. My script
Trying to get a simple COUNT from a table that takes a couple of
I'm trying to get some simple code working to log the pitch, roll, and
I'm trying to get a simple sort function going using anonymous functions. One each
I'm trying to get a simple bookmarklet working with Rails that creates a form
Im trying to get a simple SQL statement in my code, and get a
I am trying to get a simple regex to verify that a URL contains
I'm trying to get a simple solution for this layout. This is the simplified

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.