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

  • Home
  • SEARCH
  • 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 6181569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:02:56+00:00 2026-05-24T01:02:56+00:00

I have an Excel Macro as follows: Private Sub CommandButton1_Click() Application.ScreenUpdating = False Dim

  • 0

I have an Excel Macro as follows:

Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Dim i&, j&, k&, LR_A&, LR_B&, LR_C&, count&

LR_A = Range("A" & Rows.count).End(xlUp).Row
LR_B = Range("B" & Rows.count).End(xlUp).Row
LR_C = Range("C" & Rows.count).End(xlUp).Row
count = 1

For i = 1 To LR_A
  For j = 1 To LR_B
     For k = 1 To LR_C
        Range("D" & count).Value = Range("A" & i).Value
        Range("E" & count).Value = Range("B" & j).Value
        Range("F" & count).Value = Range("C" & k).Value
        count = count + 1
     Next k
  Next j
Next i
Application.ScreenUpdating = True
End Sub

As you can see, it is resorting the data in columns A, B, and C into D, E, and F.

What code do I need to add to get it to ignore the column headers in A, B, and C? I have searched around but have been unable to find an answer.

In addition, how would I change it so that it instead of resorting the data into D, E, and F, it is resorting it into A, B, and C on another worksheet?

This is my first macro, so they are pretty basic questions.

Thanks in advance

  • 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-05-24T01:02:58+00:00Added an answer on May 24, 2026 at 1:02 am

    Answer to your question

    To avoid copying the headers, you should begin your loops at index 2.
    To copy values to another Worksheet, you need to call it in your Range.

    For i = 2 To LR_A
      For j = 2 To LR_B
         For k = 2 To LR_C
            Sheets("My other ws").Range("D" & count).Value = Range("A" & i).Value
            Sheets("My other ws").Range("E" & count).Value = Range("B" & j).Value
            Sheets("My other ws").Range("F" & count).Value = Range("C" & k).Value
            count = count + 1
         Next k
      Next j
    Next i
    

    Maybe a better way to handle this case

    Looping over range using index can be very slow.
    I advise you to have a look at this link: http://www.ozgrid.com/VBA/VBALoops.htm where the author explained faster ways to loop over ranges.

    Some tips

    Have a look at Excel SpecialCells as described here.
    For instance, in your case, you could try to use ActiveSheet.UsedRange instead of finding the last used row.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the below stored in excel macro:- Sub Sales() Dim StrSQl As String
I have an Excel 2010 macro application that is made up of several workbook
I have written an Excel VBA macro which imports data from a HTML file
I have made a minor change to an Excel macro, and although it worked
I have an Excel 2003 workbook that contains a macro to copy certain of
I have an Excel file that has a bunch of VBA and macro code
I have created a macro for excel which will pop up form that contains
I have a chart in a Worksheet in Excel and I have a macro
We have an Excel 2002/XP based application that interacts with SQL 2000/5 to process
I have an Excel file with macro. In this file, there is a user

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.