How to remove 400 error from clear even rows/text to columns macro?

qplsn9

New Member
Joined
Dec 5, 2023
Messages
8
Office Version
  1. 365
Platform
  1. Windows
I made this macro that will take a string of text (ex: Test.12048.210384.193287) from a scanned QR code in cell A2 and will perform a text to column function on the string to separate by a period delimiter "." to put "Test" in cell A2, 12048 in cell B2, so on and so forth with the text string. The code works and involves more code to prevent a data override message for each row but when it finishes I receive a 400 error. Is something in my code causing this?

VBA Code:
Sub DisableAlerts()
    Application.DisplayAlerts = False
Dim row_num As Long
For i = 2 To 100 Step 2
    Range("A" & i).TextToColumns Destination:=Range("A" & i), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
        :=".", FieldInfo:=Array(1, 1), TrailingMinusNumbers:=True
Next i
    Application.DisplayAlerts = True
End Sub

I also have a macro that clears all even rows so row A2, A4, A6, etc. This also gives me a 400 error when it is finished but it functions perfectly fine. Any idea why?

VBA Code:
Sub cleareven()
For i = 2 To ActiveSheet.UsedRange.Rows.Count Step 2
Rows(i).ClearContents
Next i
End Sub
 

Attachments

  • Screenshot 2024-01-16 104632.png
    Screenshot 2024-01-16 104632.png
    5.1 KB · Views: 7

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
It shouldn't be the cause of your error, but in your first procedure, you declared a variable named "row_num", but then you are using a variable named "i" to loop through your range (which you have NOT declared). So I you really should change those variables to match.

Do you have any other VBA code in your sheet that many be interfering, especially any event procedure code in the "Sheet" module of your VB Editor?
 
Upvote 0

Forum statistics

Threads
1,215,072
Messages
6,122,966
Members
449,094
Latest member
Anshu121

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