Forum Discussion

D_Marshall514's avatar
D_Marshall514
Copper Contributor
May 09, 2024
Solved

Run-Time Error '1004': Method 'Range' of object '_global' failed?

I have a macro that is supposed to take a cell (starting with J8), perform the text to columns function (placing the data in 2 columns starting with J8) and then go down two rows (to J10) and perform...
  • OliverScheurich's avatar
    May 09, 2024

    D_Marshall514 

    Sub texttocolumns()
    
    Application.DisplayAlerts = False
    Application.ScreenUpdating = False
    Dim currentcell As Variant
    
    Set currentcell = Cells(8, 10)
    
    Do While Not IsEmpty(currentcell)
    
      currentcell.texttocolumns Destination:=currentcell, _
      ConsecutiveDelimiter:=True, Space:=True
       
      Set currentcell = currentcell.Offset(2, 0)
       
    Loop
    
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    
    End Sub

    This macro works in the attached sample file. The dimension of currentcell must be Variant according to the Microsoft documentation.

    Range.TextToColumns-Methode (Excel) | Microsoft Learn

     

Resources