VBA Bug Error

VbaHell

Well-known Member
Joined
Jan 30, 2011
Messages
1,220
Hello all, I am using Excel 2007
I am trying to learn VBA which I find a challenge but also very interesting at the same time.
the code below keeps buging out on the Text to columns, also if there is a more efficient way to improve this that would be great, open to any help please


Sub UpdateData()
Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
With Range("E:E")
Selection.TextToColumns Destination:=Range("E1"), DataType:=xlDelimited
.Value = Evaluate("if(row(" & .Address & "), text(" & .Address & ", ""mmmm""))")
End With
Columns("P:P").TextToColumns Destination:=Range("P1"), DataType:=xlDelimited
Range("AO1").FormulaR1C1 = "Site Name"
Range("AO2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-25],'Site Name'!C[-40]:C[-39],2,FALSE)"
Selection.AutoFill Destination:=Range("AO2:AO" & LR), Type:=xlFillDefault
Columns("AO:AO").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A1").Select

End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
You have 2 code line references to "Text to columns"; Which one causes the problem?
and What is the reported Error?
 
Upvote 0
Jim, thank you for replying on this


This is the Runtime Error 1004 which is on this line of code
Selection.TextToColumns Destination:=Range("E1"), DataType:=xlDelimited
 
Upvote 0
Range reference looks like it got lost in translation:
Code:
With Range("E:E")
[COLOR="Red"]Selection[/COLOR].TextToColumns Destination:=Range("E1"), DataType:=xlDelimited
.Value = Evaluate("if(row(" & .Address & "), text(" & .Address & ", ""mmmm""))")
End With

Try instead:
Code:
With Range("E:E")
.TextToColumns Destination:=Range("E1"), DataType:=xlDelimited
.Value = Evaluate("if(row(" & .Address & "), text(" & .Address & ", ""mmmm""))")
End With

What's the IF(Row(),Text()) supposed to be doing?
 
Upvote 0
I am attemping to turn the date format in a text value of the month IE: 2/3/2012 would be March if that makes sense
 
Upvote 0
Hmm, so why not just format the dates to show as March? Why does the values have to be literal text?
ξ
 
Upvote 0
I have some Countifs matching against the months, if I format these cells as the month it shows as the month but the cell value is still as the actual date. Also the dates in the report are formatted as 02/03/12 (2nd March 2012) and Excel sometimes get's confused as an american date format. (Feb 3rd 2012)
I am new to VBA so if you know a better way to solve this I would really appreciate your help
 
Upvote 0
What are you using for the delimiter in Text to columns?

Or are you not using it to split a column of data out?
 
Upvote 0
Hi Norie

I am not using it to split a column of data out. To be honest with you are I am grasping at straws with this. I think the text to columns isn't doing anything other than formatting the cell to 2/3/2012 instead of the existing value of 2/3/12
 
Upvote 0

Forum statistics

Threads
1,203,625
Messages
6,056,398
Members
444,862
Latest member
more_resource23

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