VBA code to reset after execution or to end command

Robert_G

New Member
Joined
Jul 13, 2018
Messages
48
I have a spreadsheet where I copy and paste a comma separated text like this example:

24.034,6475.00,82.5,1945.18,1223.76,12.42,1,0,-37.1,
31.405,8454.00,83.3,1943.86,1937.10,12.41,1.5895,0,-0.3,
124.005,1562.00,83.2,90.96,89.30,0.58,1.5895,0,-1.8,
124.662,1562.00,83.2,90.48,89.03,0.58,1.5895,0,-1.6,



In my spreadsheet I have this code with to a command button that separates the data into columns with headings.



Private Sub CommandButton1_Click()


Dim objRange1 As Range


'Set up the ranges
Set objRange1 = Range("a23:a49")


'Do the first parse
objRange1.TextToColumns _
Destination:=Range("e2"), _
DataType:=xlDelimited, _
Tab:=False, _
Semicolon:=False, _
Comma:=True, _
Space:=False, _
Other:=False, _
OtherChar:="-"




End Sub




The problem I have is the code and command works great except if I copy and paste another comma separated text, it formats it automatically and places it in the wrong area.

I'm trying to figure out how to either to reset the code before I paste the new data or if it's going to automatically separate the data, is to have it at least format back to range E2 where I had specified.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Code:
Sub ResetTTC()
  On Error Resume Next
  With Cells(Rows.Count, Columns.Count)
    .Value = "Texas"
    .TextToColumns Destination:=.Cells, _
                   DataType:=xlDelimited, _
                   TextQualifier:=xlDoubleQuote, _
                   ConsecutiveDelimiter:=False, _
                   Tab:=True, _
                   Semicolon:=False, _
                   Comma:=False, _
                   Space:=False, _
                   Other:=False, _
                   TrailingMinusNumbers:=True, _
                   FieldInfo:=Array(1, 1)
    .Clear
    .Worksheet.UsedRange
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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