Create Data Base

urubag

New Member
Joined
Aug 17, 2021
Messages
18
Office Version
  1. 365
Platform
  1. Windows
Hi VBA Developers,

Hope you are fine,

Please note I have been trying to create a database but in this case, I only need a column with the data, based on some parameters but during the process I am confused since the code I think should have some loops.
Probably my code is a mess, but definitely create database manually or using formulas could be painful. If someone highly skilled can help me with the code I will appreciate a lot, I just need to create the database 1 time.

Basically, there is a specific structure with a Pattern (Expected results Spoiler) but this example

VBA Code:
Sub CreateHier()

With Application

'.ScreenUpdating = False
.EnableEvents = False
.DisplayAlerts = False

Dim ws, Ts As Worksheet
Dim i, W, L, lastrow, LastR1 As Long
Dim X, Y, Z, O As String
Dim Cell As Range

Set ws = Sheets("Data")
Set Ts = Sheets("Template")
lastrow = ws.Range("A" & Rows.Count).End(xlUp).Row


For i = 2 To lastrow

ws.Select
Range("A1").Select

ActiveCell.Offset(1, 0).Activate

X = ActiveCell.Offset(0, 1).Value & "_"
Y = ActiveCell.Offset(0, 2).Value & "_"
Z = ActiveCell.Offset(0, 3).Value


LastR1 = Ts.Range("C" & .Rows.Count).End(xlUp).Row + 1

Ts.Cells(LastR1, 3).Value = X & Y & Z

    For W = 2 To lastrow

        ActiveCell.Offset(1, 0).Activate

        X = ActiveCell.Offset(0, 1).Value & "_"
        Y = ActiveCell.Offset(0, 2).Value & "_"
        O = ActiveCell.Offset(0, 4).Value
   
        LastR1 = Ts.Range("A" & .Rows.Count).End(xlUp).Row + 1

        Ts.Cells(LastR1, 3).Value = X & Y & O
       
        'For Each Cell In Range("I2:I10")
       
            For P = 2 To lastrow
       
            ActiveCell.Select
       
            X = ActiveCell.Offset(0, 1).Value & "_"
            Y = ActiveCell.Offset(0, 2).Value & "_"
            Y = ActiveCell.Offset(0, 6).Value
           
            Ts.Cells(LastR1, 3).Value = X & Y
           
           
           
           
           
           
            Next P
           
        'Next Cell
       
       
       
    Next W
   
Next i

'.ScreenUpdating = False
.EnableEvents = False
.DisplayAlerts = False

End With
End Sub



CountryDivisionCountry CdTotalPNLProduct CodeProduct NameCountryCompany Code
BelizeGHHBZTTLPNLOOVOncology VaccineBZ2200
Costa RicaGHHCRTTLPNLFCVPharmacology VaccineBZ2220
El SalvadorGHHSVTTLPNLNEUNeuroscienceBZ2240
GuatemalaGHHGTTTLPNLPHTPulmonary HypertensionBZ2260
HondurasGHHHNTTLPNLIMHImmunologyUS1000
MexicoGHHMXTTLPNLCRDCardiovascularUS1010
NicaraguaGHHNITTLPNLMTBMetabolismUS1020
PanamaGHHPATTLPNLTPATherapeuticUS1030
ArgentinaGHHARTTLPNLNDGNeurodegenerative CureCA1100
BoliviaGHHBVTTLPNLCA1110
BrazilGHHBRTTLPNLCA1120
ChileGHHCHTTLPNLCA1130
ColombiaGHHCOTTLPNLCR2000
EcuadorGHHECTTLPNLCR2010
French GuianaGHHFGTTLPNLCR2020
GuyanaGHHGYTTLPNLCR2030
ParaguayGHHPGTTLPNLSV2300
PeruGHHPETTLPNLSV2310
SurinameGHHSRTTLPNLSV2320
UruguayGHHUUTTLPNLSV2330
VenezuelaGHHVZTTLPNLGT2400
United StatesGHHUSTTLPNLGT2410
CanadaGHHCATTLPNLGT2420
GT2430
HN2500
HN2510
HN2520
HN2530
MX2600
MX2610
MX2620
MX2630
AR3000
AR3010
AR3020
AR3030
BV3100
BV3110
BV3120
BV3130
BR3500
BR3510
BR3520
BR3530
CH3600
CH3610
CH3620
CH3630
CO3700
CO3710
CO3720
CO3730
EC3800
EC3810
EC3820
EC3830
FG3200
FG3210
FG3220
FG3230
GY3300
GY3310
GY3320
GY3330
PG3900
PG3910
PG3920
PG3930
PE4000
PE4010
PE4020
PE4030
SR4100
SR4110
SR4120
SR4130
UU4200
UU4210
UU4220
UU4230
VZ4300
VZ4310
VZ4320
VZ4330



"Expected Results Yellow"

Expected Results
GHH_BZ_TTL
GHH_BZ_OOC_PNLNumbers Code is a mix Between company code based on country code (Data) and those code below as 1001 , 1002 etc
GHH_BZ_OOCDynamicDefault
2200100122001001
2220100122201001
2240100122401001
2260100122601001
GHH_BZ_OOV_PNL
GHH_BZ_OOV
2200100222001002
2220100222201002
2240100222401002
2260100222601002
GHH_BZ_FCV_PNL
GHH_BZ_FCV
2200100322001003
2220100322201003
2240100322401003
2260100322601003
GHH_BZ_FCV_NEU
GHH_BZ_NEU
2200100422001004
2220100422201004
2240100422401004
2260100422601004
GHH_BZ_FCV_PHT
GHH_BZ_PHT
2200100522001005
2220100522201005
2240100522401005
2260100522601005
GHH_BZ_IMH_PHT
GHH_BZ_IMH
2200100622001006
2220100622201006
2240100622401006
2260100622601006
GHH_BZ_CRD_PHT
GHH_BZ_CRD
2200100722001007
2220100722201007
2240100722401007
2260100722601007
GHH_BZ_MTB_PNL
GHH_BZ_MTB
2200100822001008
2220100822201008
2240100822401008
2260100822601008
GHH_BZ_TPA_PNL
GHH_BZ_TPA
2200100922001009
2220100922201009
2240100922401009
2260100922601009
GHH_BZ_NDG_PNL
GHH_BZ_NDG
2200101022001010
2220101022201010
2240101022401010
2260101022601010



Expected Column is the only required as results.

Appreciate your help on this.

Regards
Andres A
 
Last edited by a moderator:

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hi MVP owner please close this post I already found a way to do it
 
Upvote 0
There will be people that are looking for a solution for the same problem.
They will be oh so glad if they end up here and indeed find the solution.
Would you be so inclined to help these people just like you were looking for help by showing your solution?
 
Upvote 0

Forum statistics

Threads
1,217,047
Messages
6,134,278
Members
449,862
Latest member
Muhamad Irfandi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top