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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:52:23+00:00 2026-06-13T15:52:23+00:00

Creating macros in Excel is not my strong point so I’m wondering if someone

  • 0

Creating macros in Excel is not my strong point so I’m wondering if someone is able to help.

I have a small table with product values, though not every cell has a value. What I’m trying to do is write a macro to create a list on a separate sheet. The macro I have written works for the first column but that’s where it stops.

For example

List | aa | bb   | cc

a    |1   | 15   |  -

b    |2   | 23   | 12

c    |-   | 17   | 5

d    |4   | -    | -

Should appear on Sheet 2 like so

- List| aa
- a   | 1
- b   | 2
- d   | 4
- List| bb
- a   | 15
- b   | 23
- c   | 17
- List| cc
- b   | 12
- c   | 5

At the moment, only aa shows correctly on the 2nd sheet and none of the other columns.

The macro I have so far is

Sub Button2_Click()
    Dim Column As Integer
    Column = 1
    newrow = 1
    Do Until Worksheets("Sheet1").Cells(Column, 1).Value = ""

        If Worksheets("Sheet1").Cells(Column, 2).Value <> "" Then

            Worksheets("Sheet2").Cells(newrow, 1).Value = Worksheets("Sheet1").Cells(Column, 1).Value
            Worksheets("Sheet2").Cells(newrow, 2).Value = Worksheets("Sheet1").Cells(Column, 2).Value

            newrow = newrow + 1
        End If
        Column = Column + 1
    Loop

End Sub
  • 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-13T15:52:24+00:00Added an answer on June 13, 2026 at 3:52 pm

    This is what I was suggesting. This code sample is based on the above sample data. If the structure of the sample changes then you will have to amend the code accordingly. I have commented the code so that you shouldn’t have a problem understanding it. But if you do, simply post back 🙂

    CODE

    Option Explicit
    
    Sub Sample()
        '~~> Input/Output Sheets
        Dim wsI As Worksheet, wsO As Worksheet
        Dim Lrow As Long, ORow As Long, i As Long
        Dim rngToFilter As Range
    
        '~~> Set the input, output sheets
        Set wsI = ThisWorkbook.Sheets("Sheet1")
        Set wsO = ThisWorkbook.Sheets("Sheet2")
    
        '~~> Set the output row in the new sheet
        ORow = 1
    
        With wsI
            '~~> Get last row in Col A
            Lrow = .Range("A" & .Rows.Count).End(xlUp).Row
    
            '~~> Set your range
            Set rngToFilter = .Range("A1:D" & Lrow)
    
            '~~> Hide Col C to E
            .Range("C:E").EntireColumn.Hidden = True
    
            '~~> Loop through Col B to Col D
            For i = 2 To 4
    
                '~~> Remove any filters
                .AutoFilterMode = False
    
                '~~> Copy Header viz List| aa, List| bb
                Union(.Cells(1, 1), .Cells(1, i)).Copy wsO.Range("A" & ORow)
    
                '~~> Get next empty row
                ORow = ORow + 1
    
                '~~> Filter, offset(to exclude headers) and copy visible rows
                With rngToFilter
                    .AutoFilter Field:=i, Criteria1:="<>"
    
                    '~~> Copy the filtered results to the new sheet
                    .Offset(1, 0).SpecialCells(xlCellTypeVisible).Copy wsO.Range("A" & ORow)
                End With
    
                ORow = wsO.Range("A" & wsO.Rows.Count).End(xlUp).Row + 1
    
                '~~> Unhide/Hide relevant columns
                .Columns(i).EntireColumn.Hidden = True
                .Columns(i + 1).EntireColumn.Hidden = False
    
                '~~> Remove any filters
                .AutoFilterMode = False
            Next i
    
            '~~> Unhide all columns
            .Range("B:E").EntireColumn.Hidden = False
        End With
    End Sub
    

    SCREENSHOT

    enter image description here

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

Sidebar

Related Questions

Currently I am creating VBA Macros for Excel and recently have started using UserForms.
I have the following couple of C pre-processor macros for creating test functions: //
I need help creating a string editing macro for excel in visual basic. I
I have been creating macros and saving them for later use with the following
I'm creating a spreadsheet to train my numerical skills. Now, I use VBA macros
I find it really useful to record temporary keyboard macros to help with day
There's a bunch of special macros that MFC uses when creating dialogs, and in
I am creating a logging facility for my library, and have made some nice
Lately I have been creating PowerPoint presentations to companies. I have mostly been doing
I have seen programs exporting to Excel in two different ways. Opening Excel and

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.