How do i convert a text to column code block into a loop?
up vote
0
down vote
favorite
I'm using the following codes repeatedly to text to column some data. I'm repeating these lines from ("A:A") to ("DM:DM"). Sometimes the file i want to run this on will have less that that amount of columns. Even if that's the case i made the code to text to column the maximum possible amount of columns. But this makes the execution slow. I want to convert this to a loop where if the next column is blank, the execution will jump to the next block.
Can you good people suggest me a way to do that?
Range("A:A").TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
Thank you!
excel vba excel-vba
add a comment |
up vote
0
down vote
favorite
I'm using the following codes repeatedly to text to column some data. I'm repeating these lines from ("A:A") to ("DM:DM"). Sometimes the file i want to run this on will have less that that amount of columns. Even if that's the case i made the code to text to column the maximum possible amount of columns. But this makes the execution slow. I want to convert this to a loop where if the next column is blank, the execution will jump to the next block.
Can you good people suggest me a way to do that?
Range("A:A").TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
Thank you!
excel vba excel-vba
You can use offset, so in a loopfor x=1 to 10 if range("a1").offset(0,x).value<>"" then Range("A:A").offset(0,x).texttocolumns....else skip
Or simplycolumns(x).
– Nathan_Sav
Nov 14 at 11:56
Sofor x=1 to 10 if range("a1").offset(0,x).value<>"" then Range("A:A").offset(0,x).texttocolumns Destination:=Range("A1"), DataType:=xlDelimited, _ TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _ Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _ :=Array(1, 1), TrailingMinusNumbers:=True
? Also can you explain what each line does?
– Nick Razzleflamm
Nov 15 at 11:13
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm using the following codes repeatedly to text to column some data. I'm repeating these lines from ("A:A") to ("DM:DM"). Sometimes the file i want to run this on will have less that that amount of columns. Even if that's the case i made the code to text to column the maximum possible amount of columns. But this makes the execution slow. I want to convert this to a loop where if the next column is blank, the execution will jump to the next block.
Can you good people suggest me a way to do that?
Range("A:A").TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
Thank you!
excel vba excel-vba
I'm using the following codes repeatedly to text to column some data. I'm repeating these lines from ("A:A") to ("DM:DM"). Sometimes the file i want to run this on will have less that that amount of columns. Even if that's the case i made the code to text to column the maximum possible amount of columns. But this makes the execution slow. I want to convert this to a loop where if the next column is blank, the execution will jump to the next block.
Can you good people suggest me a way to do that?
Range("A:A").TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
Thank you!
excel vba excel-vba
excel vba excel-vba
asked Nov 14 at 11:41
Nick Razzleflamm
84
84
You can use offset, so in a loopfor x=1 to 10 if range("a1").offset(0,x).value<>"" then Range("A:A").offset(0,x).texttocolumns....else skip
Or simplycolumns(x).
– Nathan_Sav
Nov 14 at 11:56
Sofor x=1 to 10 if range("a1").offset(0,x).value<>"" then Range("A:A").offset(0,x).texttocolumns Destination:=Range("A1"), DataType:=xlDelimited, _ TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _ Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _ :=Array(1, 1), TrailingMinusNumbers:=True
? Also can you explain what each line does?
– Nick Razzleflamm
Nov 15 at 11:13
add a comment |
You can use offset, so in a loopfor x=1 to 10 if range("a1").offset(0,x).value<>"" then Range("A:A").offset(0,x).texttocolumns....else skip
Or simplycolumns(x).
– Nathan_Sav
Nov 14 at 11:56
Sofor x=1 to 10 if range("a1").offset(0,x).value<>"" then Range("A:A").offset(0,x).texttocolumns Destination:=Range("A1"), DataType:=xlDelimited, _ TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _ Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _ :=Array(1, 1), TrailingMinusNumbers:=True
? Also can you explain what each line does?
– Nick Razzleflamm
Nov 15 at 11:13
You can use offset, so in a loop
for x=1 to 10 if range("a1").offset(0,x).value<>"" then Range("A:A").offset(0,x).texttocolumns....else skip
Or simply columns(x).
– Nathan_Sav
Nov 14 at 11:56
You can use offset, so in a loop
for x=1 to 10 if range("a1").offset(0,x).value<>"" then Range("A:A").offset(0,x).texttocolumns....else skip
Or simply columns(x).
– Nathan_Sav
Nov 14 at 11:56
So
for x=1 to 10 if range("a1").offset(0,x).value<>"" then Range("A:A").offset(0,x).texttocolumns Destination:=Range("A1"), DataType:=xlDelimited, _ TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _ Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _ :=Array(1, 1), TrailingMinusNumbers:=True
? Also can you explain what each line does?– Nick Razzleflamm
Nov 15 at 11:13
So
for x=1 to 10 if range("a1").offset(0,x).value<>"" then Range("A:A").offset(0,x).texttocolumns Destination:=Range("A1"), DataType:=xlDelimited, _ TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _ Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _ :=Array(1, 1), TrailingMinusNumbers:=True
? Also can you explain what each line does?– Nick Razzleflamm
Nov 15 at 11:13
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
To check if a column has any non-blank cells (formula or value) you could employ this condition:
If Range("A:A").SpecialCells(xlCellTypeBlanks).CountLarge < Range("A:A").CountLarge Then
which will allow you to determine if a column is populated in any way and only execute your code if it is.
Be warned that the call to SpecialCells will fail if the entire column is non-blank.
add a comment |
up vote
0
down vote
accepted
I played around with the code a bit and came up with this solution. I don't know if there is any better way to do this but this gets the job done.
If anyone is interested:
On Error Resume Next
For x = 1 To 200
If Not Range("a1").Offset(0, x).IsEmpty(ActiveCell.Value) Then
Range("A:A").Offset(0, x).TextToColumns Destination:=Range("A1").Offset(0, x), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True,
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
Next x
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
To check if a column has any non-blank cells (formula or value) you could employ this condition:
If Range("A:A").SpecialCells(xlCellTypeBlanks).CountLarge < Range("A:A").CountLarge Then
which will allow you to determine if a column is populated in any way and only execute your code if it is.
Be warned that the call to SpecialCells will fail if the entire column is non-blank.
add a comment |
up vote
0
down vote
To check if a column has any non-blank cells (formula or value) you could employ this condition:
If Range("A:A").SpecialCells(xlCellTypeBlanks).CountLarge < Range("A:A").CountLarge Then
which will allow you to determine if a column is populated in any way and only execute your code if it is.
Be warned that the call to SpecialCells will fail if the entire column is non-blank.
add a comment |
up vote
0
down vote
up vote
0
down vote
To check if a column has any non-blank cells (formula or value) you could employ this condition:
If Range("A:A").SpecialCells(xlCellTypeBlanks).CountLarge < Range("A:A").CountLarge Then
which will allow you to determine if a column is populated in any way and only execute your code if it is.
Be warned that the call to SpecialCells will fail if the entire column is non-blank.
To check if a column has any non-blank cells (formula or value) you could employ this condition:
If Range("A:A").SpecialCells(xlCellTypeBlanks).CountLarge < Range("A:A").CountLarge Then
which will allow you to determine if a column is populated in any way and only execute your code if it is.
Be warned that the call to SpecialCells will fail if the entire column is non-blank.
answered Nov 14 at 12:11
NeepNeepNeep
66047
66047
add a comment |
add a comment |
up vote
0
down vote
accepted
I played around with the code a bit and came up with this solution. I don't know if there is any better way to do this but this gets the job done.
If anyone is interested:
On Error Resume Next
For x = 1 To 200
If Not Range("a1").Offset(0, x).IsEmpty(ActiveCell.Value) Then
Range("A:A").Offset(0, x).TextToColumns Destination:=Range("A1").Offset(0, x), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True,
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
Next x
add a comment |
up vote
0
down vote
accepted
I played around with the code a bit and came up with this solution. I don't know if there is any better way to do this but this gets the job done.
If anyone is interested:
On Error Resume Next
For x = 1 To 200
If Not Range("a1").Offset(0, x).IsEmpty(ActiveCell.Value) Then
Range("A:A").Offset(0, x).TextToColumns Destination:=Range("A1").Offset(0, x), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True,
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
Next x
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
I played around with the code a bit and came up with this solution. I don't know if there is any better way to do this but this gets the job done.
If anyone is interested:
On Error Resume Next
For x = 1 To 200
If Not Range("a1").Offset(0, x).IsEmpty(ActiveCell.Value) Then
Range("A:A").Offset(0, x).TextToColumns Destination:=Range("A1").Offset(0, x), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True,
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
Next x
I played around with the code a bit and came up with this solution. I don't know if there is any better way to do this but this gets the job done.
If anyone is interested:
On Error Resume Next
For x = 1 To 200
If Not Range("a1").Offset(0, x).IsEmpty(ActiveCell.Value) Then
Range("A:A").Offset(0, x).TextToColumns Destination:=Range("A1").Offset(0, x), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True,
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
Next x
edited Nov 19 at 6:57
answered Nov 19 at 6:51
Nick Razzleflamm
84
84
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53299425%2fhow-do-i-convert-a-text-to-column-code-block-into-a-loop%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You can use offset, so in a loop
for x=1 to 10 if range("a1").offset(0,x).value<>"" then Range("A:A").offset(0,x).texttocolumns....else skip
Or simplycolumns(x).
– Nathan_Sav
Nov 14 at 11:56
So
for x=1 to 10 if range("a1").offset(0,x).value<>"" then Range("A:A").offset(0,x).texttocolumns Destination:=Range("A1"), DataType:=xlDelimited, _ TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _ Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _ :=Array(1, 1), TrailingMinusNumbers:=True
? Also can you explain what each line does?– Nick Razzleflamm
Nov 15 at 11:13