Question on using VBA to copy text and paste in appropriate columns

MiteshG

New Member
Joined
Sep 12, 2022
Messages
23
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Hi,

I have data in text format in an excel sheet (Sheet1) which looks like below.
Country or region: Albania
Last update: 12 May 2023
Status of enactment
No announcement yet
Income Inclusion Rule (IIR)
Entry into force: To be confirmed
No announcement yet
Undertaxed Payments Rule (UTPR)
Entry into force: To be confirmed
No announcement yet
Qualified Domestic Minimum Top-up Tax (QDMTT)
Entry into force: To be confirmed
No announcement yet
Covered Taxes
No information available.
Qualifying Refundable Tax Credits
No information available.
Transitional Safe Harbour
No information available.
Compliance / Filing Requirements
No information available.

I am looking to arrange the data in table format as below in a new sheet
Country or regionStatus of enactmentIncome Inclusion Rule (IIR)Undertaxed Payments Rule (UTPR)Qualified Domestic Minimum Top-up Tax (QDMTT)Covered TaxesQualifying Refundable Tax CreditsTransitional Safe HarbourCompliance / Filing Requirements
AlbaniaNo announcement yetEntry into force: To be confirmedEntry into force: To be confirmedEntry into force: To be confirmedNo information available.No information available.No information available.No information available.
No announcement yetNo announcement yetNo announcement yet

How to achieve this with TextToColumns VBA functionality. This same step is to be repeated for 70 countries
 
Book6
ABCDEFGHI
2Country or regionStatus of enactmentIncome Inclusion Rule (IIR)Undertaxed Payments Rule (UTPR)Qualified Domestic Minimum Top-up Tax (QDMTT)Covered TaxesQualifying Refundable Tax CreditsTransitional Safe HarbourCompliance / Filing Requirements
3AlbaniaNo announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetNo information available.No information available.No information available.No information available.
4AngolaNo announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetNo information available.No information available.No information available.No information available.
5ArgentinaNo announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetNo information available.No information available.No information availableNo information available.
6ArmeniaNo announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetNo information available.No information available.No information availableNo information available
7AustraliaIn the 2023-24 Budget, the Government announced the implementation of a 15% global minimum tax and domestic minimum tax, key aspects of Pillar Two of the OECD/G20 Two-Pillar Solution to address the tax challenges arising from the digitalisation of the economy. The IIR will apply for fiscal years starting on or after 1 January 2024. The UTPR will apply for fiscal years starting on or after 1 January 2025. The domestic minimum tax will apply for income years starting on or after 1 January 2024. The draft legislation has not been released yet.Entry into force: 1 January 2024 The IIR will apply to fiscal years that begin on or after 1 January 2024 to: Multinational groups with annual global revenue of EUR750 million or more. In-scope multinationals across all sectors subject to certain exclusions for investment funds, pension funds, government entities, international organisations, not-for-profit organisations, as defined in the OECD Global anti- Base Erosion (GloBE) Rules, and income associated with international shippingEntry into force: 1 January 2025 The UTPR will apply to fiscal years that begin on or after 1 January 2025 to: Multinational groups with annual global revenue of EUR750 million or more. In-scope multinationals across all sectors subject to certain exclusions for investment funds, pension funds, government entities, international organisations, not-for-profit organisations, as defined in the OECD Global anti- Base Erosion (GloBE) Rules, and income associated with international shippingEntry into force: 1 January 2024 The domestic minimum tax will apply to fiscal years that begin on or after 1 January 2024 to: Australian operations of multinational groups with annual global revenue of EUR750 million or more. In-scope multinationals across all sectors subject to certain exclusions for investment funds, pension funds, government entities, international organisations, not-for-profit organisations, as defined in the OECD Global anti- Base Erosion (GloBE) Rules, and income associated with international shippingNo information available.No information available.No information availableNo information available. Federal Budget 2023-24 - Australia will implement key aspects of the OECD's 'Pillar Two' framework, including a domestic minimum tax, with an effective date for some measures from 1 January 2024. Read more
Sheet2


VBA Code:
Option Compare Text
Option Explicit
Sub test()
Dim ws As Worksheet
Dim ws2 As Worksheet
Dim a As Variant
Dim c%, i%, m%
Dim ss As Range
Dim rec As String
Dim savenum%
Dim dict As Object

Set ws = Sheets("Sheet1")
Set ws2 = Sheets("sheet2")

Set dict = CreateObject("Scripting.Dictionary")
dict.comparemode = vbTextCompare

ReDim b(1 To 5000, 1 To 9)

a = ws.Range("a168:a" & ws.Cells(Rows.Count, "A").End(xlUp).Row).Value 'Start filtering data from A168
c = 1

ws2.[a3:i10000].Clear

For Each ss In ws2.Range("a2:i2")
    dict.Add ss.Value, ss.Column
Next ss

For i = 1 To UBound(a, 1)
    If InStr(a(i, 1), "country") >= 1 Then
         If m > savenum Then
                savenum = m
            End If
        c = 1 + savenum
        b(c, 1) = a(i, 1)
        savenum = 0
    ElseIf dict.exists(a(i - 1, 1)) Then
        b(c, dict(a(i - 1, 1))) = a(i, 1)
            If m > savenum Then
                savenum = m
            End If
        m = c
        rec = a(i - 1, 1)
 
   ElseIf Not InStr(a(i, 1), "last update") >= 1 And Not dict.exists(a(i, 1)) Then
        'm = m + 1 this one for now not running, because only one single row instead of offset rows
       b(m, dict(rec)) = a(i, 1)
 
    End If
 
Next i

ws2.[a3].Resize(UBound(b, 1), UBound(b, 2)).Value = b
ws2.Columns("A").Replace what:="Country or region: ", replacement:="", searchorder:=xlByColumns

End Sub

Hi @MiteshG , Kindly give a shot in sheet2 (do make sure a2:i2 columns are being filled -country, status of enactment, etc) .

I only hide this line (comment)

'm = m + 1 this one for now not running, because desire output only one single row instead of offset rows.
Thank you again for your response. I tried to execute this and got output as below. For the headings where there is text that is spanning more than 1 rows, the output seems to have only last line as below
Country or regionStatus of enactmentIncome Inclusion Rule (IIR)
AustraliaThe draft legislation has not been released yet.Base Erosion (GloBE) Rules, and income associated with international shipping
 
Upvote 0

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Thank you again for your response. I tried to execute this and got output as below. For the headings where there is text that is spanning more than 1 rows, the output seems to have only last line as below
Country or regionStatus of enactmentIncome Inclusion Rule (IIR)
AustraliaThe draft legislation has not been released yet.Base Erosion (GloBE) Rules, and income associated with international shipping

sheet1 data is starting from a168 correct? Meanwhile sheet2 columns are from A2:I2?

Would you mind to share the file instead into the dropbox/gdrive for further checking?
 
Upvote 0
Book6
ABCDEFGHI
2Country or regionStatus of enactmentIncome Inclusion Rule (IIR)Undertaxed Payments Rule (UTPR)Qualified Domestic Minimum Top-up Tax (QDMTT)Covered TaxesQualifying Refundable Tax CreditsTransitional Safe HarbourCompliance / Filing Requirements
3AlbaniaNo announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetNo information available.No information available.No information available.No information available.
4AngolaNo announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetNo information available.No information available.No information available.No information available.
5ArgentinaNo announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetNo information available.No information available.No information availableNo information available.
6ArmeniaNo announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetNo information available.No information available.No information availableNo information available
7AustraliaIn the 2023-24 Budget, the Government announced the implementation of a 15% global minimum tax and domestic minimum tax, key aspects of Pillar Two of the OECD/G20 Two-Pillar Solution to address the tax challenges arising from the digitalisation of the economy. The IIR will apply for fiscal years starting on or after 1 January 2024. The UTPR will apply for fiscal years starting on or after 1 January 2025. The domestic minimum tax will apply for income years starting on or after 1 January 2024. The draft legislation has not been released yet.Entry into force: 1 January 2024 The IIR will apply to fiscal years that begin on or after 1 January 2024 to: Multinational groups with annual global revenue of EUR750 million or more. In-scope multinationals across all sectors subject to certain exclusions for investment funds, pension funds, government entities, international organisations, not-for-profit organisations, as defined in the OECD Global anti- Base Erosion (GloBE) Rules, and income associated with international shippingEntry into force: 1 January 2025 The UTPR will apply to fiscal years that begin on or after 1 January 2025 to: Multinational groups with annual global revenue of EUR750 million or more. In-scope multinationals across all sectors subject to certain exclusions for investment funds, pension funds, government entities, international organisations, not-for-profit organisations, as defined in the OECD Global anti- Base Erosion (GloBE) Rules, and income associated with international shippingEntry into force: 1 January 2024 The domestic minimum tax will apply to fiscal years that begin on or after 1 January 2024 to: Australian operations of multinational groups with annual global revenue of EUR750 million or more. In-scope multinationals across all sectors subject to certain exclusions for investment funds, pension funds, government entities, international organisations, not-for-profit organisations, as defined in the OECD Global anti- Base Erosion (GloBE) Rules, and income associated with international shippingNo information available.No information available.No information availableNo information available. Federal Budget 2023-24 - Australia will implement key aspects of the OECD's 'Pillar Two' framework, including a domestic minimum tax, with an effective date for some measures from 1 January 2024. Read more
8AustriaNo announcement yet. Austria has to implement the Pillar Two rules in line with the Council Directive (EU) 2022/2523 of 14 December 2022 on ensuring a global minimum level of taxation for multinational enterprise groups and large-scale domestic groups in the Union.Entry into force: To be confirmed No announcement yet. It is expected that Austria will follow the overall implementation timeline proposed by the Directive (EU) 2022/2523 of 14 December 2022, i.e., 2024 for the IIR and 2025 for the UTPR.Entry into force: To be confirmed No announcement yet. It is expected that Austria will follow the overall implementation timeline proposed by the Directive (EU) 2022/2523 of 14 December 2022, i.e., 2024 for the IIR and 2025 for the UTPR.Entry into force: To be confirmed No announcement yet. Austria can adopt a QDMTT as part of its overall implementation of Pillar Two under Art. 11 of the Directive (EU) 2022/2523 of 14 December 2022No information available.No information available.No information availableNo information available.
9AzerbaijanNo announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetNo information available.No information available.No information availableNo information available
10BahamasOn May 17 the Bahamas government published a public consultation gthe Green Paper on Corporate Income Tax Strategies for the Bahamash, which sets out the options under consideration for transitioning away from the existing business licence tax (BTL) regime, as well as implementing changes to address Pillar TwoEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetNo information available.No information available.No information availableNo information available
11BahrainNo announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetNo information availableNo information available.No information availableNo information available
12BarbadosThe Prime Minister announced In the Budgetary Proposals and Financial Statement 2023 on 14 March 2023 that the Government was deep in consultations with the Barbados Revenue Authority. The Prime Minister indicated that she would likely come back to the country within six months on this issue.Entry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetNo information availableNo information availableNo information available.No information available.
13BelgiumThe Belgian Minister of Finance has announced a phased tax reform, with one phase dedicated to Pillar Two enactment in Belgium. Currently, stakeholder consultations are taking place with advisors and businesses. Draft legislation is expected to be published in the summer 2023, with a vote shortly after that. In general, the Pillar Two implementation will be in line with the OECD model rules and the Council Directive (EU) 2022/2523 of 14 December 2022 on ensuring a global minimum level of taxation for multinational enterprise groups and large-scale domestic groups in the Union. The government already agreed on some core principles of the Pillar Two implementation in Belgium including a decision that a QDMTT will be introduced, that the Pillar Two QDMTT will be payable in the course of the year (via the Belgian tax prepayment system) and that the R&D tax credit will be modified to qualify as a qualifying tax credit.Entry into force: 1 January 2024 It is expected that Belgium will follow the overall implementation timeline proposed by the Directive (EU) 2022/2523 of 14 December 2022, i.e., 2024 for the IIR and 2025 for the UTPR.Entry into force: 1 January 2025 It is expected that Belgium will follow the overall implementation timeline proposed by the Directive (EU) 2022/2523 of 14 December 2022, i.e., 2024 for the IIR and 2025 for the UTPR.Entry into force: To be confirmed Most likely Belgium will include a QDMTT in the draft legislation.No information available.The Government has expressed that the R&D tax credit will be modified to qualify as a qualifying tax credit.It is expected that Belgium will follow the Transitional Safe Harbour guidance included in the Implementation Framework issued by the OECD in December 2022.No information available. Belgium agrees on core principles for implementation of the Global Minimum Tax (GloBE/Pillar 2) for MNEfs and some additional tax measures The Belgian government reached an agreement on the Federal budget. After long discussions within the government, a number of measures have been decided that will reduce expenditures and measures that will increase revenue. Read more
14BermudaIn the 2023 Budget, the Bermuda Premier announced plans for the second half of 2023 on a decision in relation to Pillar Two (and potentially a QDMTT) and the 8,000 exempted companies in Bermuda which are in possession of a certificate from the Bermuda Government that states that they will not be charged taxes on their income until 2035 (should an income tax be enacted). There is a committee of industry representatives formed with a report to the Government for consideration due this Summer 2023 (June / July).Entry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetNo information availableNo information availableNo information availableNo information available.
Sheet2


VBA Code:
Option Compare Text
Option Explicit
Sub test()
Dim ws As Worksheet
Dim ws2 As Worksheet
Dim a As Variant
Dim c%, i%, m%
Dim ss As Range
Dim rec As String
Dim savenum%
Dim dict As Object

Set ws = Sheets("Sheet1")
Set ws2 = Sheets("sheet2")

Set dict = CreateObject("Scripting.Dictionary")
dict.comparemode = vbTextCompare

ReDim b(1 To 5000, 1 To 9)

a = ws.Range("a1:a" & ws.Cells(Rows.Count, "A").End(xlUp).Row).Value 'Start filtering data from A168
c = 1

ws2.[a3:i10000].Clear

For Each ss In ws2.Range("a2:i2")
    dict.Add ss.Value, ss.Column
Next ss

For i = 1 To UBound(a, 1)
   If Left(a(i, 1), 10) = "country or" Then
         If m > savenum Then
                savenum = m
            End If
        c = 1 + savenum
        b(c, 1) = a(i, 1)
        savenum = 0
    ElseIf dict.exists(a(i - 1, 1)) Then
        b(c, dict(a(i - 1, 1))) = a(i, 1)
            If m > savenum Then
                savenum = m
            End If
        m = c
        rec = a(i - 1, 1)
 
   ElseIf Not InStr(a(i, 1), "last update") >= 1 And Not dict.exists(a(i, 1)) Then
        'm = m + 1 this one for now not running, because only one single row instead of offset rows
       b(m, dict(rec)) = a(i, 1)
 
    End If
 
Next i

ws2.[a3].Resize(UBound(b, 1), UBound(b, 2)).Value = b
ws2.Columns("A").Replace what:="Country or region: ", replacement:="", searchorder:=xlByColumns
ws2.Cells.WrapText = true 
End Sub
 
Upvote 0
Book6
ABCDEFGHI
2Country or regionStatus of enactmentIncome Inclusion Rule (IIR)Undertaxed Payments Rule (UTPR)Qualified Domestic Minimum Top-up Tax (QDMTT)Covered TaxesQualifying Refundable Tax CreditsTransitional Safe HarbourCompliance / Filing Requirements
3AlbaniaNo announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetNo information available.No information available.No information available.No information available.
4AngolaNo announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetNo information available.No information available.No information available.No information available.
5ArgentinaNo announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetNo information available.No information available.No information availableNo information available.
6ArmeniaNo announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetNo information available.No information available.No information availableNo information available
7AustraliaIn the 2023-24 Budget, the Government announced the implementation of a 15% global minimum tax and domestic minimum tax, key aspects of Pillar Two of the OECD/G20 Two-Pillar Solution to address the tax challenges arising from the digitalisation of the economy. The IIR will apply for fiscal years starting on or after 1 January 2024. The UTPR will apply for fiscal years starting on or after 1 January 2025. The domestic minimum tax will apply for income years starting on or after 1 January 2024. The draft legislation has not been released yet.Entry into force: 1 January 2024 The IIR will apply to fiscal years that begin on or after 1 January 2024 to: Multinational groups with annual global revenue of EUR750 million or more. In-scope multinationals across all sectors subject to certain exclusions for investment funds, pension funds, government entities, international organisations, not-for-profit organisations, as defined in the OECD Global anti- Base Erosion (GloBE) Rules, and income associated with international shippingEntry into force: 1 January 2025 The UTPR will apply to fiscal years that begin on or after 1 January 2025 to: Multinational groups with annual global revenue of EUR750 million or more. In-scope multinationals across all sectors subject to certain exclusions for investment funds, pension funds, government entities, international organisations, not-for-profit organisations, as defined in the OECD Global anti- Base Erosion (GloBE) Rules, and income associated with international shippingEntry into force: 1 January 2024 The domestic minimum tax will apply to fiscal years that begin on or after 1 January 2024 to: Australian operations of multinational groups with annual global revenue of EUR750 million or more. In-scope multinationals across all sectors subject to certain exclusions for investment funds, pension funds, government entities, international organisations, not-for-profit organisations, as defined in the OECD Global anti- Base Erosion (GloBE) Rules, and income associated with international shippingNo information available.No information available.No information availableNo information available. Federal Budget 2023-24 - Australia will implement key aspects of the OECD's 'Pillar Two' framework, including a domestic minimum tax, with an effective date for some measures from 1 January 2024. Read more
8AustriaNo announcement yet. Austria has to implement the Pillar Two rules in line with the Council Directive (EU) 2022/2523 of 14 December 2022 on ensuring a global minimum level of taxation for multinational enterprise groups and large-scale domestic groups in the Union.Entry into force: To be confirmed No announcement yet. It is expected that Austria will follow the overall implementation timeline proposed by the Directive (EU) 2022/2523 of 14 December 2022, i.e., 2024 for the IIR and 2025 for the UTPR.Entry into force: To be confirmed No announcement yet. It is expected that Austria will follow the overall implementation timeline proposed by the Directive (EU) 2022/2523 of 14 December 2022, i.e., 2024 for the IIR and 2025 for the UTPR.Entry into force: To be confirmed No announcement yet. Austria can adopt a QDMTT as part of its overall implementation of Pillar Two under Art. 11 of the Directive (EU) 2022/2523 of 14 December 2022No information available.No information available.No information availableNo information available.
9AzerbaijanNo announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetNo information available.No information available.No information availableNo information available
10BahamasOn May 17 the Bahamas government published a public consultation gthe Green Paper on Corporate Income Tax Strategies for the Bahamash, which sets out the options under consideration for transitioning away from the existing business licence tax (BTL) regime, as well as implementing changes to address Pillar TwoEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetNo information available.No information available.No information availableNo information available
11BahrainNo announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetNo information availableNo information available.No information availableNo information available
12BarbadosThe Prime Minister announced In the Budgetary Proposals and Financial Statement 2023 on 14 March 2023 that the Government was deep in consultations with the Barbados Revenue Authority. The Prime Minister indicated that she would likely come back to the country within six months on this issue.Entry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetNo information availableNo information availableNo information available.No information available.
13BelgiumThe Belgian Minister of Finance has announced a phased tax reform, with one phase dedicated to Pillar Two enactment in Belgium. Currently, stakeholder consultations are taking place with advisors and businesses. Draft legislation is expected to be published in the summer 2023, with a vote shortly after that. In general, the Pillar Two implementation will be in line with the OECD model rules and the Council Directive (EU) 2022/2523 of 14 December 2022 on ensuring a global minimum level of taxation for multinational enterprise groups and large-scale domestic groups in the Union. The government already agreed on some core principles of the Pillar Two implementation in Belgium including a decision that a QDMTT will be introduced, that the Pillar Two QDMTT will be payable in the course of the year (via the Belgian tax prepayment system) and that the R&D tax credit will be modified to qualify as a qualifying tax credit.Entry into force: 1 January 2024 It is expected that Belgium will follow the overall implementation timeline proposed by the Directive (EU) 2022/2523 of 14 December 2022, i.e., 2024 for the IIR and 2025 for the UTPR.Entry into force: 1 January 2025 It is expected that Belgium will follow the overall implementation timeline proposed by the Directive (EU) 2022/2523 of 14 December 2022, i.e., 2024 for the IIR and 2025 for the UTPR.Entry into force: To be confirmed Most likely Belgium will include a QDMTT in the draft legislation.No information available.The Government has expressed that the R&D tax credit will be modified to qualify as a qualifying tax credit.It is expected that Belgium will follow the Transitional Safe Harbour guidance included in the Implementation Framework issued by the OECD in December 2022.No information available. Belgium agrees on core principles for implementation of the Global Minimum Tax (GloBE/Pillar 2) for MNEfs and some additional tax measures The Belgian government reached an agreement on the Federal budget. After long discussions within the government, a number of measures have been decided that will reduce expenditures and measures that will increase revenue. Read more
14BermudaIn the 2023 Budget, the Bermuda Premier announced plans for the second half of 2023 on a decision in relation to Pillar Two (and potentially a QDMTT) and the 8,000 exempted companies in Bermuda which are in possession of a certificate from the Bermuda Government that states that they will not be charged taxes on their income until 2035 (should an income tax be enacted). There is a committee of industry representatives formed with a report to the Government for consideration due this Summer 2023 (June / July).Entry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetEntry into force: To be confirmed No announcement yetNo information availableNo information availableNo information availableNo information available.
Sheet2


VBA Code:
Option Compare Text
Option Explicit
Sub test()
Dim ws As Worksheet
Dim ws2 As Worksheet
Dim a As Variant
Dim c%, i%, m%
Dim ss As Range
Dim rec As String
Dim savenum%
Dim dict As Object

Set ws = Sheets("Sheet1")
Set ws2 = Sheets("sheet2")

Set dict = CreateObject("Scripting.Dictionary")
dict.comparemode = vbTextCompare

ReDim b(1 To 5000, 1 To 9)

a = ws.Range("a1:a" & ws.Cells(Rows.Count, "A").End(xlUp).Row).Value 'Start filtering data from A168
c = 1

ws2.[a3:i10000].Clear

For Each ss In ws2.Range("a2:i2")
    dict.Add ss.Value, ss.Column
Next ss

For i = 1 To UBound(a, 1)
   If Left(a(i, 1), 10) = "country or" Then
         If m > savenum Then
                savenum = m
            End If
        c = 1 + savenum
        b(c, 1) = a(i, 1)
        savenum = 0
    ElseIf dict.exists(a(i - 1, 1)) Then
        b(c, dict(a(i - 1, 1))) = a(i, 1)
            If m > savenum Then
                savenum = m
            End If
        m = c
        rec = a(i - 1, 1)
 
   ElseIf Not InStr(a(i, 1), "last update") >= 1 And Not dict.exists(a(i, 1)) Then
        'm = m + 1 this one for now not running, because only one single row instead of offset rows
       b(m, dict(rec)) = a(i, 1)
 
    End If
 
Next i

ws2.[a3].Resize(UBound(b, 1), UBound(b, 2)).Value = b
ws2.Columns("A").Replace what:="Country or region: ", replacement:="", searchorder:=xlByColumns
ws2.Cells.WrapText = true
End Sub
Thank you so much again for your response but I seem to be getting only the last line in case there are multiple lines under any heading. Attaching the sample -
Extract_Specific_Data_from_PDF_to_Excel.xlsm
ABCDEFG
2Country or regionStatus of enactmentIncome Inclusion Rule (IIR)Undertaxed Payments Rule (UTPR)Qualified Domestic Minimum Top-up Tax (QDMTT)Covered TaxesQualifying Refundable Tax Credits
3AlbaniaNo announcement yetNo announcement yetNo announcement yetNo announcement yetNo information available.No information available.
4AngolaNo announcement yetNo announcement yetNo announcement yetNo announcement yetNo information available.No information available.
5ArgentinaNo announcement yetNo announcement yetNo announcement yetNo announcement yetNo information available.No information available.
6ArmeniaNo announcement yetNo announcement yetNo announcement yetNo announcement yetNo information available.No information available.
7AustraliaThe draft legislation has not been released yet.Base Erosion (GloBE) Rules, and income associated with international shippingBase Erosion (GloBE) Rules, and income associated with international shippingBase Erosion (GloBE) Rules, and income associated with international shippingNo information available.No information available.
8Austriaand large-scale domestic groups in the Union.Directive (EU) 2022/2523 of 14 December 2022, i.e., 2024 for the IIR and 2025 for the UTPR.Directive (EU) 2022/2523 of 14 December 2022, i.e., 2024 for the IIR and 2025 for the UTPR.of the Directive (EU) 2022/2523 of 14 December 2022No information available.No information available.
9AzerbaijanNo announcement yetNo announcement yetNo announcement yetNo announcement yetNo information available.No information available.
10Bahamasbusiness licence tax (BTL) regime, as well as implementing changes to address Pillar TwoNo announcement yetNo announcement yetNo announcement yetNo information available.No information available.
11BahrainNo announcement yetNo announcement yetNo announcement yetNo announcement yetNo information availableNo information available.
12Barbadoswould likely come back to the country within six months on this issue.No announcement yetNo announcement yetNo announcement yetNo information availableNo information available
13Belgiumthe Belgian tax prepayment system) and that the R&D tax credit will be modified to qualify as a qualifying tax credit.of 14 December 2022, i.e., 2024 for the IIR and 2025 for the UTPR.of 14 December 2022, i.e., 2024 for the IIR and 2025 for the UTPR.Most likely Belgium will include a QDMTT in the draft legislation.No information available.The Government has expressed that the R&D tax credit will be modified to qualify as a qualifying tax credit.
Sheet2
 
Upvote 0
Apologies for the confusion, Please use this one instead.

b(m, dict(rec)) = b(m, dict(rec)) & " " & a(i, 1)

Forgot to paste the changed code earlier

VBA Code:
Option Compare Text
Option Explicit
Sub test()
Dim ws As Worksheet
Dim ws2 As Worksheet
Dim a As Variant
Dim c%, i%, m%
Dim ss As Range
Dim rec As String
Dim savenum%
Dim dict As Object

Set ws = Sheets("Sheet1")
Set ws2 = Sheets("sheet2")

Set dict = CreateObject("Scripting.Dictionary")
dict.comparemode = vbTextCompare

ReDim b(1 To 5000, 1 To 9)

a = ws.Range("a1:a" & ws.Cells(Rows.Count, "A").End(xlUp).Row).Value 'Start filtering data from A168
c = 1

ws2.[a3:i10000].Clear

For Each ss In ws2.Range("a2:i2")
    dict.Add ss.Value, ss.Column
Next ss

For i = 1 To UBound(a, 1)
   If Left(a(i, 1), 10) = "country or" Then
         If m > savenum Then
                savenum = m
            End If
        c = 1 + savenum
        b(c, 1) = a(i, 1)
        savenum = 0
    ElseIf dict.exists(a(i - 1, 1)) Then
        b(c, dict(a(i - 1, 1))) = a(i, 1)
            If m > savenum Then
                savenum = m
            End If
        m = c
        rec = a(i - 1, 1)
 
   ElseIf Not InStr(a(i, 1), "last update") >= 1 And Not dict.exists(a(i, 1)) Then
        'm = m + 1 this one for now not running, because only one single row instead of offset rows
       b(m, dict(rec)) = b(m, dict(rec)) & " " & a(i, 1)
 
    End If
 
Next i

ws2.[a3].Resize(UBound(b, 1), UBound(b, 2)).Value = b
ws2.Columns("A").Replace what:="Country or region: ", replacement:="", searchorder:=xlByColumns
ws2.Cells.WrapText = true
End Sub
 
Upvote 0
Solution
Apologies for the confusion, Please use this one instead.

b(m, dict(rec)) = b(m, dict(rec)) & " " & a(i, 1)

Forgot to paste the changed code earlier

VBA Code:
Option Compare Text
Option Explicit
Sub test()
Dim ws As Worksheet
Dim ws2 As Worksheet
Dim a As Variant
Dim c%, i%, m%
Dim ss As Range
Dim rec As String
Dim savenum%
Dim dict As Object

Set ws = Sheets("Sheet1")
Set ws2 = Sheets("sheet2")

Set dict = CreateObject("Scripting.Dictionary")
dict.comparemode = vbTextCompare

ReDim b(1 To 5000, 1 To 9)

a = ws.Range("a1:a" & ws.Cells(Rows.Count, "A").End(xlUp).Row).Value 'Start filtering data from A168
c = 1

ws2.[a3:i10000].Clear

For Each ss In ws2.Range("a2:i2")
    dict.Add ss.Value, ss.Column
Next ss

For i = 1 To UBound(a, 1)
   If Left(a(i, 1), 10) = "country or" Then
         If m > savenum Then
                savenum = m
            End If
        c = 1 + savenum
        b(c, 1) = a(i, 1)
        savenum = 0
    ElseIf dict.exists(a(i - 1, 1)) Then
        b(c, dict(a(i - 1, 1))) = a(i, 1)
            If m > savenum Then
                savenum = m
            End If
        m = c
        rec = a(i - 1, 1)
 
   ElseIf Not InStr(a(i, 1), "last update") >= 1 And Not dict.exists(a(i, 1)) Then
        'm = m + 1 this one for now not running, because only one single row instead of offset rows
       b(m, dict(rec)) = b(m, dict(rec)) & " " & a(i, 1)
 
    End If
 
Next i

ws2.[a3].Resize(UBound(b, 1), UBound(b, 2)).Value = b
ws2.Columns("A").Replace what:="Country or region: ", replacement:="", searchorder:=xlByColumns
ws2.Cells.WrapText = true
End Sub
Thank you so much for your help. Working fine now. Again, thanks a lot for all the help.
 
Upvote 0
Thank you so much for your help. Working fine now. Again, thanks a lot for all the help.

Glad to assist, If you have any further questions, please don't hesitate to ask/share with us :)
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

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