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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:59:46+00:00 2026-06-14T15:59:46+00:00

Hello, I am doing a macro that copy the values on the columns, VALUES1,

  • 0

enter image description here

Hello, I am doing a macro that copy the values on the columns, VALUES1, VALUES2, VALUES3 if it is not blank when the ARTICLE is the same.

I would have the first spreadsheet and I want the macro to return the second Spreadsheet.

I have managed how to make it:

Sub test()

Dim i, last, j, x As Integer
Dim R As Range

last = Sheets("List2").Range("A100000").End(xlUp).Row - 2

For i = 0 To last

    Set R = Sheets("List2").Range("A2")

        If Not WorksheetFunction.CountIf(Sheets("List2").Columns(1), _
        Sheets("List2").Range("A2").Offset(i, 0).Value) = 0 Then

            For j = 1 To WorksheetFunction.CountIf(Sheets("List2").Columns(1), _

                Sheets("List2").Range("A2").Offset(i, 0).Value)
                Set R = Sheets("List2").Columns(1).Find(Sheets("List2").Range("A2"). _
                Offset(i, 0).Value, R, LookAt:=xlWhole)

                    For x = 0 To 2

                        If Not Sheets("List2").Range("B2").Offset(i, x).Value = "" Then

                            R.Offset(0, "1" + x).Value = Sheets("List2"). _ 
                            Range("B2").Offset(i, x).Value

                        End If
                    Next x
            Next j
        End If
Next i

End Sub

but the problem it takes too long, ’cause I have around 10.000 Rows and 20 Columns, and besides the Spreadsheet is not in order, so it could be to has a disorder, something like (A, B, B, A, …)

Is there any way to make it faster o better???

Thanks a lot. Themolestones.

  • 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-14T15:59:47+00:00Added an answer on June 14, 2026 at 3:59 pm

    Here is a very easy solution with formulas to your problem:

    Sheet2!A1=Sheet1!A1
    Sheet2!B1=SUMIF(Sheet1!$A:$A,Sheet2!$A1,Sheet1!B:B)
    
    Sheet2!C1=SUMIF(Sheet1!$A:$A,Sheet2!$A1,Sheet1!C:C)
    Sheet2!D1=SUMIF(Sheet1!$A:$A,Sheet2!$A1,Sheet1!D:D)
    

    Put these formulas in the cells left of the = and copy down. You really need only the first two, because you can copy the second also to the right.

    You need Sheet1 to be sorted by article.

    That’s it.

    Of course, there might be occasions, when it is just necessary to implement this with VBA. Usually the fastest way to handle large amounts of cells with VBA, is to use array-copies of your ranges. Using worksheet-functions and looping through single cell references slows you down heavily.

    Edit:

    This would be my VBA solution

    Public Sub Demo()
      Dim arrRange() As Variant
      Dim arrRangeResult() As Variant
      Dim i As Long
      Dim j As Long
      Dim copyVal As Variant
      Dim copyCond As Variant
      Dim copyCol As Long
    
      'create two copies of the origin data
      arrRange = Range("A:D")
      arrRangeResult = Range("A:D")
    
      'loop through first data-copy, downwards through the articles
      For i = LBound(arrRange, 1) + 1 To UBound(arrRange, 1)
        'stop loop, if no article was found
        If arrRange(i, 1) = "" Then Exit For
        'store current article ID
        copyCond = arrRange(i, 1)
        'loop sideways through value-columns
        For j = LBound(arrRange, 2) + 1 To UBound(arrRange, 2)
          'store value & column, when found
          If arrRange(i, j) <> "" Then
            copyVal = arrRange(i, j)
            copyCol = j
            Exit For
          End If
        Next j
    
        'loop through output array and paste value
        For j = LBound(arrRangeResult, 1) + 1 To UBound(arrRangeResult, 1)
          If arrRangeResult(j, 1) = copyCond Then
            'paste-down found value to all occurences of article
            arrRangeResult(j, copyCol) = copyVal
          ElseIf arrRangeResult(j, 1) = "" Then
            'early stop, when no article ID is found
            Exit For
          End If
        Next j
      Next i
    
      'create output
      Range("K:N") = arrRangeResult
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I thought that doing @f def g(): print 'hello' is exactly the same as
Currently I am doing this: I have text that looks like: Hello ${user.name}, this
I am doing a tutorial according to this article . This is basic Hello
EDIT: I would like to avoid doing something like this: var str = 'Hello';
Hello I am doing a program that will notice when a specific key is
Hello I am doing a simple toggle that hides and shows certain blocks of
Hello I don t know if I am doing something wrong or not but
Hello. I need help with doing a mysql select, where the values in wins
Hello everybody, I'm a newbie and I'm doing a code that the principal aim
Hello i'm doing a application in php, and i have a list of items

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.