VBA - Texttocolumns- Loop through currentregion

krshnn

New Member
Joined
Mar 23, 2022
Messages
17
Office Version
  1. 2013
Platform
  1. Windows
My requirement is that I have a range of cells which begins in B4 and ends in R507 (R507 is dynamic ; It could be s557 or af201 in another report).
I want to do text to columns vba to each used columns

Currently I'm writing code in this fashion which is pretty rudimentary and without loop
Range("B4").Select
Range(Selection, Selection.End(xlDown)).TextToColumns , xlDelimited, xlTextQualifierDoubleQuote, True, True
Range("c4").Select
Range(Selection, Selection.End(xlDown)).TextToColumns , xlDelimited, xlTextQualifierDoubleQuote, True, True
Range("d4").Select
Range(Selection, Selection.End(xlDown)).TextToColumns , xlDelimited, xlTextQualifierDoubleQuote, True, True
Range("e4").Select
Range(Selection, Selection.End(xlDown)).TextToColumns , xlDelimited, xlTextQualifierDoubleQuote, True, True

Basically, I want the above code in a loop wherein it starts in B4 column and ends in last used column.

And btw, is there an efficient way to select cells from start of the range to end of the range.
I'm currently writing two lines of code to achieve that objective.
Range("B4").select
Range(selection,selection.end(xldown)).select
I would like the above two lines of code in a single code.

Thanks in advance.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Might helps
VBA Code:
Sub tester()
    Dim i&
    For i = 2 To Cells(4, Columns.Count).End(xlToLeft).Column
        Range(Cells(4, i), Cells(4, i).End(xlDown)).TextToColumns , xlDelimited, xlTextQualifierDoubleQuote, True, True
    Next
End Sub
 
Upvote 0
Solution
Bro thanks for your assistance. It worked. But I made slight tweaks to avoid errors while executing

VBA Code:
Sub tester()
Dim i As Integer

On Error Resume Next
    For i = 2 To Cells(4, Columns.Count).End(xlToRight).Column
        Range(Cells(4, i), Cells(4, i).End(xlDown)).TextToColumns , xlDelimited, xlTextQualifierDoubleQuote, True, True
    Next
On Error GoTo 0

End Sub
 
Upvote 0
Great
And thank you for the feed back
Be happy And safe
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,313
Members
452,634
Latest member
cpostell

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