Macro run time error 9, out of range error

cadandcode

Board Regular
Joined
Jan 21, 2023
Messages
125
Office Version
  1. 2019
Platform
  1. Windows
  2. Mobile
Hi, when I try to save a macro and run it, code gives that error.

VBA Code:
Sub MakroKantar()
'
' MakroKantar Makro
'

'
    Columns("D:K").Select
    Selection.Delete Shift:=xlToLeft
    Range("F:F,H:H").Select
    Range("H1").Activate
    Selection.Delete Shift:=xlToLeft
    Columns("E:E").Select
    Selection.Cut
    Columns("D:D").Select
    Selection.Insert Shift:=xlToRight
    Columns("H:K").Select
    Selection.ColumnWidth = 10
    Range("H2").Select
    Windows("1GÜN FORMÜL.xlsx").Activate
    Range("B2:E30").Select
    Selection.Copy
    Windows("25^J01^J2023.xlsx").Activate
    ActiveSheet.Paste
    Range("M30").Select
End Sub
 

Attachments

  • Adsız2222.png
    Adsız2222.png
    52.2 KB · Views: 7

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
It is having a problem with this line:

VBA Code:
Windows("1GÜN FORMÜL.xlsx").Activate

It probably means that the referenced window ("1GÜN FORMÜL.xlsx") has been closed as so cannot be activated.
 
Upvote 0
It is having a problem with this line:

VBA Code:
Windows("1GÜN FORMÜL.xlsx").Activate

It probably means that the referenced window ("1GÜN FORMÜL.xlsx") has been closed as so cannot be activated.
Isnt it working like functions in excel? Like getting a data from a cell from another file without opening it?
 
Upvote 0
Isnt it working like functions in excel? Like getting a data from a cell from another file without opening it?
No. A window or a workbook is an object, The window must exist and/or the workbook must be open to be referenced. If workbook 1GÜN FORMÜL.xlsx is not open you cannot reference it with a statement like Windows("1GÜN FORMÜL.xlsx").Activate. To do that you must have code to find and open the file "1GÜN FORMÜL.xlsx"

This test code will help you to examine which workbooks are open.

VBA Code:
Sub ListOpenWorkbooks()
    Dim WB As Workbook
    Dim W As Window
    Dim Msg As String, I As Long
    
    I = 0
    For Each WB In Application.Workbooks
        I = I + 1
        Msg = Msg & I & ". " & WB.Name & vbCr
    Next WB
    
    MsgBox "List of open WORKBOOKS:" & vbCr & vbCr & Msg, vbOKOnly Or vbInformation, "Workbook Names"
    
        Msg = ""
        I = 0
    For Each W In Application.Windows
        I = I + 1
        Msg = Msg & I & ". " & W.Caption & vbCr
    Next W
    
    MsgBox "List of open WINDOWS:" & vbCr & vbCr & Msg, vbOKOnly Or vbInformation, "Window Captions"
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

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