VBA Excel Databaseization

Asked 2 years ago, Updated 2 years ago, 137 views

Excel has data organized by date in the first column and ID in the first column.
I would like to organize this so that it can be used as a database, but please let me know if there is a VBA code that can be used in Excel.I was wondering if I could do it with Transpose.

Original Data

 2016 2015 2014....        
A Suzuki Yamada Tanaka 
B Takai Kuroi Nakano
C Tako Yano Sano 

Databaseization

A2016 Suzuki
A2015 Yamada
A2014 Tanaka
B2016 Takai
B2015 Kuroi
.
.
.
.
C2014 Sano

I'm a beginner, but I'm going to check the meaning of the code myself.

database excel vba

2022-09-30 21:27

1 Answers

It's rough, but it looks like the following.
Please create two sheets in Excel and enter the data on the first sheet.
The second page displays the results.

Subconvert()
Dim inputWS As Worksheet
DimputWS As Worksheet

Dim year As String
Dimid As String
Dim name As String

Dim num As Integer

Set inputWS=Sheets(1)
Set outputWS=Sheets(2)

num = 1

For Row=2 To 4
    Forcol=2 To 4

        year=inputWS.Cells(1,col).Value
        id=inputWS.Cells(Row,1).Value
        name = inputWS.Cells(Row,col).Value

        outputWS.Cells(num,1).Value=id
        outputWS.Cells(num,2).Value=year
        outputWS.Cells(num,3).Value=name

        num = num+1
    Next col
Next Row

End Sub


2022-09-30 21:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.