How use TextToColumns in Win32com - win32com

I would like a exemple how to use TextToColumns in Win32com
Sub VBA_Code()
Columns("A").TextToColumns DataType:=xlDelimited, FieldInfo:=Array(1, xlDMYFormat)
End Sub

I solved my own question using code below
xw.Range('A:A').api.TextToColumns()
Thanks

Related

Not able to use a variable inside Find command in VBA

I have a string s which contains "subham$"
Now using excel's built in command find i like to know the position of the dollar symbol,there might be other ways but i like to use find in vba code and use a variable inside it
Sub testfind()
Dim s As String
s = "subham$"
Sheets("Sheet1").Select
Range("A1").Select
ActiveCell.FormulaR1C1 = "=FIND(""$""," & s & ")"
End Sub
I am getting the error Application defined or object defined error,
what am I doing wrong?
I can't actually fathom what you're trying to do with the code, or why you'd be doing it, but in order to solve your problem:
You're not wrapping the string of s in quotes. Try:
Range("A1").FormulaR1C1 = "=FIND(""$"",""" & s & """)"

Application-defined or object-defined error with FormulaR1C1

I've got some code that isn't working, and have basically simplified it as much as possible for the sake of this post. I'm trying to run this macro and get an error saying
Application-defined or object-defined error
Am I missing something obvious?
Sub Test()
Range("B1").FormulaR1C1 = _
"=VLOOKUP(RC[-1],R2C6:R4C7,2,FALSE),0))"
End Sub
Thanks!
Your VLOOKUP has an extra parameter hanging off the right side.
Sub Test()
Range("B1").FormulaR1C1 = _
"=VLOOKUP(RC[-1], R2C6:R4C7, 2, FALSE)"
End Sub

VBA to remove CalulatedField from Pivot Table

I'm trying to write some code to add and then remove a calculated field to and from a Pivot Table. Below are the two pieces of code:
Sub AddPivotField()
With Worksheets(1).PivotTables("PivotTable1")
.AddDataField Worksheets(1).PivotTables( _
"PivotTable1").PivotFields("hProdUtil"), "Sum of hProdUtil"
.DataBodyRange.NumberFormat = "#0.0%"
End With
End Sub
And:
Sub RemovePivotField()
With Worksheets(1).PivotTables(1).DataFields("Sum of hProdUtil")
.Parent.PivotItems(.Name).Visible = False
End With
End Sub
The AddPivotField works fine but when I run the RemovePivotField I get the "Object doesn't support this property or method" error. Any ideas?
Thanks
Try the following code:
Sub RemovePivotField()
With Worksheets(1).PivotTables(1).DataFields("Sum of hProdUtil")
.Orientation = xlHidden
End With
End Sub
Was able to figure it out by modifying the code on https://www.thespreadsheetguru.com/blog/2014/9/27/vba-guide-excel-pivot-tables

Excel File Open Macro

So I'm trying to create a Macro That will update a cell when the file is opened. I'm getting the 424 Error and so I tried to do a better job defining my code/object but It still wasn't succesfull. I think I'm missing/overlooking something really easy but I can't figure it out and this is my first project so I'm trying to learn and gain a better understanding then just googling a segment of code that will work.
Private Sub Auto_Open()
Dim Try1 As String
Try1 = ActivateSheet.Cells(3, 2).Select
Tryl = "-"
' My first attempt is shown below
'
'Sheets("Current Calc").Activate
'ActivateSheet.Cells(3, 2).Value = "-"
End Sub
You've got a typo in your commented code
What you have...
Sheets("Current Calc").Activate
ActivateSheet.Cells(3, 2).Value = "-"
What it should be...
Sheets("Current Calc").Activate
ActiveSheet.Cells(3, 2).Value = "-"
Also, I should mention you should avoid using .Activate and .Select unless necessary. With that being said, I'd suggest the below code instead...
Sheets("Current Calc").Cells(3, 2).Value = "-"
EDIT:
When using Auto_Open, Excel must be opened MANUALLY in order for the code to execute; thus if it is opened via VBA this event will NOT trigger. If you want an event to trigger via VBA as well as manually, I'd suggest using Workbook_Open
Try with the following sub:
Private Sub Workbook_Open()
Dim Try1 As String
Try1 = ActiveSheet.Cells(3, 2).Select
Tryl = "-"
End Sub
Some advices:
write your code in lowercase. When you change a line, your code will change to upper and lower case automatically, this way you will detect if you have some typo error.
write a function or object ant type . This will open a dropdown list, this way you will also avoid typo error.

Having Run-time-error 1004 Application defined or object defined error

I have a simple formula in vba, like this :
Sub button_fu()
Windows("H1.xlsm").Activate
Sheets("jan").Activate
Range("J3").Select
Range("J3").Formula = "=IF((VLOOKUP(C3,'[FOLLOW UP H1.xlsx]jan'!$C$8:$M$100,8,False))=1,""terhubung"",IF((VLOOKUP(C3,'[FOLLOW UP H1.xlsx]jan'!$C$8:$M$100,9,False))=1,""unreach"",IF((VLOOKUP(C3,'[FOLLOW UP H1.xlsx]jan'!$C$8:$M$100,10,False))=1,""reject"",IF((VLOOKUP(C3,'[FOLLOW UP H1.xlsx]jan'!$C$8:$M$100,11,False))=1,""workload"","""")"
End Sub
anyone hepl me, how the problem solved it?
You are missing some closing brackets in your formula:
Sub button_fu()
Windows("H1.xlsm").Activate
Sheets("jan").Activate
Range("J3").Select
Range("J3").Formula = "=IF((VLOOKUP(C3,'[FOLLOW UP H1.xlsx]jan'!$C$8:$M$100,8,False))=1,""terhubung"",IF((VLOOKUP(C3,'[FOLLOW UP H1.xlsx]jan'!$C$8:$M$100,9,False))=1,""unreach"",IF((VLOOKUP(C3,'[FOLLOW UP H1.xlsx]jan'!$C$8:$M$100,10,False))=1,""reject"",IF((VLOOKUP(C3,'[FOLLOW UP H1.xlsx]jan'!$C$8:$M$100,11,False))=1,""workload"",""""))))"
End Sub
P.S. Should "FOLLOW UP H1.xlsx" be "H1.xlsm", or do you have another workbook?