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
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Hi, It would be good if you can provide more sample data through mini sheet via XLBB with expected result for better understanding
  • Want to help your helpers by posting a small, copyable, screen shot directly in your post? XL2BB Instructions & Download (latest January 2021 v 2.0 )
Otherwise, you can share the file with us (more sample data) for further clarification by uploading it to Google Drive or Dropbox.

Book3
AB
2Country or region: Albania1
3Last update: 12 May 20232
4Status of enactment1
5No announcement yet2
6Income Inclusion Rule (IIR)1
7Entry into force: To be confirmed2
8No announcement yet3
9Undertaxed Payments Rule (UTPR)1
10Entry into force: To be confirmed2
11No announcement yet3
12Qualified Domestic Minimum Top-up Tax (QDMTT)1
13Entry into force: To be confirmed2
14No announcement yet3
15Covered Taxes1
16No information available.2
17Qualifying Refundable Tax Credits1
18No information available.2
19Transitional Safe Harbour1
20No information available.2
21Compliance / Filing Requirements1
22No information available.2
23
Sheet1


For Income Inlucsion , Qualified Domestic , Undertaxed Payments rule, is it fix 3rows? How can we define either 2rows or 3rows? Can you elaborate more?
 
Upvote 0
Extract_Specific_Data_from_PDF_to_Excel.xlsm
A
168Country or region: Albania
169Last update: 12 May 2023
170Status of enactment
171No announcement yet
172Income Inclusion Rule (IIR)
173Entry into force: To be confirmed
174No announcement yet
175Undertaxed Payments Rule (UTPR)
176Entry into force: To be confirmed
177No announcement yet
178Qualified Domestic Minimum Top-up Tax (QDMTT)
179Entry into force: To be confirmed
180No announcement yet
181Covered Taxes
182No information available.
183Qualifying Refundable Tax Credits
184No information available.
185Transitional Safe Harbour
186No information available.
187Compliance / Filing Requirements
188No information available.
189Country or region: Angola
190Last update: 9 May 2023
191Status of enactment
192No announcement yet
193Income Inclusion Rule (IIR)
194Entry into force: To be confirmed
195No announcement yet
196Undertaxed Payments Rule (UTPR)
197Entry into force: To be confirmed
198No announcement yet
199Qualified Domestic Minimum Top-up Tax (QDMTT)
200Entry into force: To be confirmed
201No announcement yet
202Covered Taxes
203No information available.
204Qualifying Refundable Tax Credits
205No information available.
206Transitional Safe Harbour
207No information available.
208Compliance / Filing Requirements
209No information available.
210Country or region: Argentina
211Last update: 11 May 2023
212Status of enactment
213No announcement yet
214Income Inclusion Rule (IIR)
215Entry into force: To be confirmed
216No announcement yet
217Undertaxed Payments Rule (UTPR)
218Entry into force: To be confirmed
219No announcement yet
220Qualified Domestic Minimum Top-up Tax (QDMTT)
221Entry into force: To be confirmed
222No announcement yet
223Covered Taxes
224No information available.
225Qualifying Refundable Tax Credits
226No information available.
227Transitional Safe Harbour
228No information available
229Compliance / Filing Requirements
230No information available.
231Country or region: Armenia
232Last update: 15 May 2023
233Status of enactment
234No announcement yet
235Income Inclusion Rule (IIR)
236Entry into force: To be confirmed
237No announcement yet
238Undertaxed Payments Rule (UTPR)
239Entry into force: To be confirmed
240No announcement yet
241Qualified Domestic Minimum Top-up Tax (QDMTT)
242Entry into force: To be confirmed
243No announcement yet
244Covered Taxes
245No information available.
246Qualifying Refundable Tax Credits
247No information available.
248Transitional Safe Harbour
249No information available
250Compliance / Filing Requirements
251No information available
252Country or region: Australia
253Last update: 9 May 2023
254Status of enactment
255In the 2023-24 Budget, the Government announced the implementation of a 15% global minimum tax and domestic
256minimum tax, key aspects of Pillar Two of the OECD/G20 Two-Pillar Solution to address the tax challenges arising
257from the digitalisation of the economy.
258The IIR will apply for fiscal years starting on or after 1 January 2024. The UTPR will apply for fiscal years starting on
259or after 1 January 2025. The domestic minimum tax will apply for income years starting on or after 1 January 2024.
260The draft legislation has not been released yet.
261Income Inclusion Rule (IIR)
262Entry into force: 1 January 2024
263The IIR will apply to fiscal years that begin on or after 1 January 2024 to:
264Multinational groups with annual global revenue of EUR750 million or more.
265In-scope multinationals across all sectors subject to certain exclusions for investment funds, pension funds,
266government entities, international organisations, not-for-profit organisations, as defined in the OECD Global anti-
267Base Erosion (GloBE) Rules, and income associated with international shipping
268Undertaxed Payments Rule (UTPR)
269Entry into force: 1 January 2025
270The UTPR will apply to fiscal years that begin on or after 1 January 2025 to:
271Multinational groups with annual global revenue of EUR750 million or more.
272In-scope multinationals across all sectors subject to certain exclusions for investment funds, pension funds,
273government entities, international organisations, not-for-profit organisations, as defined in the OECD Global anti-
274Base Erosion (GloBE) Rules, and income associated with international shipping
275Qualified Domestic Minimum Top-up Tax (QDMTT)
276Entry into force: 1 January 2024
277The domestic minimum tax will apply to fiscal years that begin on or after 1 January 2024 to:
278Australian operations of multinational groups with annual global revenue of EUR750 million or more.
279In-scope multinationals across all sectors subject to certain exclusions for investment funds, pension funds,
280government entities, international organisations, not-for-profit organisations, as defined in the OECD Global anti-
281Base Erosion (GloBE) Rules, and income associated with international shipping
282Covered Taxes
283No information available.
284Qualifying Refundable Tax Credits
285No information available.
286Transitional Safe Harbour
287No information available
288Compliance / Filing Requirements
289No information available.
290Federal Budget 2023-24 - Australia will implement key aspects of the OECD's 'Pillar Two'
291framework, including a domestic minimum tax, with an effective date for some measures from 1
292January 2024. Read more
Sheet1
 
Upvote 0
Hi, It would be good if you can provide more sample data through mini sheet via XLBB with expected result for better understanding
  • Want to help your helpers by posting a small, copyable, screen shot directly in your post? XL2BB Instructions & Download (latest January 2021 v 2.0 )
Otherwise, you can share the file with us (more sample data) for further clarification by uploading it to Google Drive or Dropbox.

Book3
AB
2Country or region: Albania1
3Last update: 12 May 20232
4Status of enactment1
5No announcement yet2
6Income Inclusion Rule (IIR)1
7Entry into force: To be confirmed2
8No announcement yet3
9Undertaxed Payments Rule (UTPR)1
10Entry into force: To be confirmed2
11No announcement yet3
12Qualified Domestic Minimum Top-up Tax (QDMTT)1
13Entry into force: To be confirmed2
14No announcement yet3
15Covered Taxes1
16No information available.2
17Qualifying Refundable Tax Credits1
18No information available.2
19Transitional Safe Harbour1
20No information available.2
21Compliance / Filing Requirements1
22No information available.2
23
Sheet1


For Income Inlucsion , Qualified Domestic , Undertaxed Payments rule, is it fix 3rows? How can we define either 2rows or 3rows? Can you elaborate more?
Thank you for your response. I have added the mini sheet. Regarding the columns Income Inclusion, QDMTT, Undertaxed Payment Rule - sometimes the text is in more than 3 rows (Australia for example in the mini sheet)
 
Upvote 0
Book3
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 confirmedEntry into force: To be confirmedEntry into force: To be confirmedNo information available.No information available.No information available.No information available.
4No announcement yetNo announcement yetNo announcement yet
5AngolaNo 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.
6No announcement yetNo announcement yetNo announcement yet
7ArgentinaNo announcement yetEntry into force: To be confirmedEntry into force: To be confirmedEntry into force: To be confirmedNo information available.No information available.No information availableNo information available.
8No announcement yetNo announcement yetNo announcement yet
9ArmeniaNo announcement yetEntry into force: To be confirmedEntry into force: To be confirmedEntry into force: To be confirmedNo information available.No information available.No information availableNo information available
10No announcement yetNo announcement yetNo announcement yet
11AustraliaIn the 2023-24 Budget, the Government announced the implementation of a 15% global minimum tax and domesticEntry into force: 1 January 2024Entry into force: 1 January 2025Entry into force: 1 January 2024No information available.No information available.No information availableNo information available.
12minimum tax, key aspects of Pillar Two of the OECD/G20 Two-Pillar Solution to address the tax challenges arisingThe IIR will apply to fiscal years that begin on or after 1 January 2024 to:The UTPR will apply to fiscal years that begin on or after 1 January 2025 to:The domestic minimum tax will apply to fiscal years that begin on or after 1 January 2024 to:Federal Budget 2023-24 - Australia will implement key aspects of the OECD's 'Pillar Two'
13from the digitalisation of the economy.Multinational groups with annual global revenue of EUR750 million or more.Multinational groups with annual global revenue of EUR750 million or more.Australian operations of multinational groups with annual global revenue of EUR750 million or more.framework, including a domestic minimum tax, with an effective date for some measures from 1
14The IIR will apply for fiscal years starting on or after 1 January 2024. The UTPR will apply for fiscal years starting onIn-scope multinationals across all sectors subject to certain exclusions for investment funds, pension funds,In-scope multinationals across all sectors subject to certain exclusions for investment funds, pension funds,In-scope multinationals across all sectors subject to certain exclusions for investment funds, pension funds,January 2024. Read more
15or after 1 January 2025. The domestic minimum tax will apply for income years starting on or after 1 January 2024.government entities, international organisations, not-for-profit organisations, as defined in the OECD Global anti-government entities, international organisations, not-for-profit organisations, as defined in the OECD Global anti-government entities, international organisations, not-for-profit organisations, as defined in the OECD Global anti-
16The 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 shipping
Sheet2


Please put the yellow highlighted columns in Sheet2,

Right click sheet2 -> view code -> paste the code below.

A little bit manual, but you may try first for reference. hopefully there's other references for you:)

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" & 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
       b(m, dict(rec)) = a(i, 1)
       
    End If
    
Next i

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

End Sub
 
Last edited:
Upvote 0
Book3
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 confirmedEntry into force: To be confirmedEntry into force: To be confirmedNo information available.No information available.No information available.No information available.
4No announcement yetNo announcement yetNo announcement yet
5AngolaNo 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.
6No announcement yetNo announcement yetNo announcement yet
7ArgentinaNo announcement yetEntry into force: To be confirmedEntry into force: To be confirmedEntry into force: To be confirmedNo information available.No information available.No information availableNo information available.
8No announcement yetNo announcement yetNo announcement yet
9ArmeniaNo announcement yetEntry into force: To be confirmedEntry into force: To be confirmedEntry into force: To be confirmedNo information available.No information available.No information availableNo information available
10No announcement yetNo announcement yetNo announcement yet
11AustraliaIn the 2023-24 Budget, the Government announced the implementation of a 15% global minimum tax and domesticEntry into force: 1 January 2024Entry into force: 1 January 2025Entry into force: 1 January 2024No information available.No information available.No information availableNo information available.
12minimum tax, key aspects of Pillar Two of the OECD/G20 Two-Pillar Solution to address the tax challenges arisingThe IIR will apply to fiscal years that begin on or after 1 January 2024 to:The UTPR will apply to fiscal years that begin on or after 1 January 2025 to:The domestic minimum tax will apply to fiscal years that begin on or after 1 January 2024 to:Federal Budget 2023-24 - Australia will implement key aspects of the OECD's 'Pillar Two'
13from the digitalisation of the economy.Multinational groups with annual global revenue of EUR750 million or more.Multinational groups with annual global revenue of EUR750 million or more.Australian operations of multinational groups with annual global revenue of EUR750 million or more.framework, including a domestic minimum tax, with an effective date for some measures from 1
14The IIR will apply for fiscal years starting on or after 1 January 2024. The UTPR will apply for fiscal years starting onIn-scope multinationals across all sectors subject to certain exclusions for investment funds, pension funds,In-scope multinationals across all sectors subject to certain exclusions for investment funds, pension funds,In-scope multinationals across all sectors subject to certain exclusions for investment funds, pension funds,January 2024. Read more
15or after 1 January 2025. The domestic minimum tax will apply for income years starting on or after 1 January 2024.government entities, international organisations, not-for-profit organisations, as defined in the OECD Global anti-government entities, international organisations, not-for-profit organisations, as defined in the OECD Global anti-government entities, international organisations, not-for-profit organisations, as defined in the OECD Global anti-
16The 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 shipping
Sheet2


Please put the yellow highlighted columns in Sheet2,

Right click sheet2 -> view code -> paste the code below.

A little bit manual, but you may try first for reference. hopefully there's other references for you:)

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" & 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
       b(m, dict(rec)) = a(i, 1)
      
    End If
   
Next i

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

End Sub
Thank you so much for your help. I am getting an error 457 - This key is already associated with an element of this collection.
dict.Add ss.Value, ss.Column
Any suggestions on how to resolve this?
 
Upvote 0
Hi @MiteshG , Needed to copy this column in A2 (sheet2).

1687533428714.png


Do you have existing column name which's being filled more than one?

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


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
       b(m, dict(rec)) = a(i, 1)
      
    End If
   
Next i

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

End Sub
 
Upvote 0
Hi @MiteshG , Needed to copy this column in A2 (sheet2).

View attachment 94140

Do you have existing column name which's being filled more than one?

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


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
       b(m, dict(rec)) = a(i, 1)
     
    End If
  
Next i

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

End Sub
Thank you. After pasting the column headings on Cell A2, the earlier error vanished. However, now getting a new error - Subscript out of range. On the below line - ElseIf dict.exists(a(i - 1, 1)) Then
 
Upvote 0
Hi @MiteshG , Needed to copy this column in A2 (sheet2).

View attachment 94140

Do you have existing column name which's being filled more than one?

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


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
       b(m, dict(rec)) = a(i, 1)
     
    End If
  
Next i

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

End Sub
Hi - I was able to resolve the error. Thank you for your help. I just had one more question - Is it possible to get the data in single row as below?

Example below
Country or regionStatus of enactmentIncome Inclusion Rule (IIR)
AlbaniaNo announcement yetEntry into force: To be confirmed No announcement yet
 
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
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.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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