Insert rows according to certain positions

Andrea Mejia

New Member
Joined
May 15, 2023
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hello everybody!
I am new doing macros in VBA and would like someone to help me please.
I have a plain txt file with the numeric positions where I should insert empty rows in an excel. How should the macro be for this scenario, considering that I don't know how to import a txt?

For example, my txt file has positions like: "20, 35, 46".
The above numbers correspond to the positions where you should insert empty rows in Excel.

I would be infinitely grateful if you could help me. thank you very much!!!!!
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Maybe
VBA Code:
Sub Del_by_txt()
Dim t As String, k, ar
    Open "D:\YOUR_TEXT_FILE.txt" For Input As #1
    While Not EOF(1)
        Line Input #1, t
        k = (Len(t) - Len(Replace(t, Chr(44), ""))) / Len(Chr(44))
        ReDim ar(1 To k + 1, 1 To 1)
        ar = Split(t, Chr(44))
            For k = UBound(ar) To 0 Step -1
                ActiveSheet.Rows(Trim(ar(k))).Delete
            Next k
    Wend
    Close #1
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,159
Messages
6,123,351
Members
449,097
Latest member
thnirmitha

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