I created a macro to insert data from an excel spreadsheet into another Excel file, but when I run the program the error "the specified dimension is not valid for the current chart type", can someone help me?
Variables (Module2)
MyRecentFile Sub
WriteCells
Program (Module1)
Variables (Module2)
Code:
Option Explicit
Public myRecentFile As String
Public counter As Integer, counter2 As Integer, ws As Integer, ws2 As Integer, res_1, res_2
Public sh As Worksheet, ch As Worksheet
Public k As Long
MyRecentFile Sub
VBA Code:
Public Sub recentFilesSpecificFolder()
res_1 = 0
res_2 = 0
counter = 1
counter2 = 4
ws2 = Workbooks("EEC QEC.xlsm").Sheets.Count
k = Workbooks("EEC QEC.xlsm").Worksheets("QEC 1.2 - montagem").Cells(Rows.Count, "H").End(xlUp).Offset(1).Row
Dim myFile As String, fileExtension As String, recentDate As Date
myDirectory = Environ("userprofile") & "\Documents\Projeto_Luis\Andre\EEC\QE"
fileExtension = "*.xls"
If Right(myDirectory, 1) <> "\" Then myDirectory = myDirectory & "\"
myFile = Dir(myDirectory & fileExtension)
If myFile <> "" Then
myRecentFile = myFile
recentDate = FileDateTime(myDirectory & myFile)
Do While myFile <> ""
If FileDateTime(myDirectory & myFile) > recentDate Then
myRecentFile = myFile
recentDate = FileDateTime(myDirectory & myFile)
End If
myFile = Dir
Loop
End If
MsgBox "Path: " & myDirectory & vbCrLf & "File: " & myMostRecentFile
ws = Workbooks(myRecentFile).Sheets.Count
Call WriteCells
End Sub
WriteCells
Code:
Public Sub WriteCells()
If counter = 16 & counter2 = 20 Then
counter = 1
Call Fill_2021
Else
Call FillSheets
End If
End Sub
Program (Module1)
VBA Code:
Set ch = Workbooks(myRecentFile).Worksheets(counter)
Set sh = Workbooks("EEC QEC.xlsm").Worksheets(counter2)
If ch.Name = "QEC 12 IF" Or ch.Name = "QEC 22 IF" Or ch.Name = "QEC 24 IF" Or ch.Name = "QEC 41 IF" Or ch.Name = "QEC 42 IF" Or ch.Name = "QEC 43 IF" Or ch.Name = "QEC 44 IF" Then
If sh.Name = "QEC 1.2 - montagem" Or sh.Name = "QEC 2.2 -SALA LIMPA" Or sh.Name = "QEC 2.4 Logística" Or sh.Name = "QEC 4.1 - MONTAGEM MANUAL(past)" Or sh.Name = "QEC 4.2 - Desmoldagem" Or sh.Name = "QEC 4,3 - RTM" Or sh.Name = "QEC 4,4 - HOT DRAPE" Then
If Range("H" & k).Value = "" Then
ch.Range("W110").Copy _
sh.Range("H" & k)
ch.Range("AI110").Copy _
sh.Range("I" & k)
Else
Do Until ActiveCell.Value = ""
ActiveCell.Offset(1).Select
res_1 = res_1 + 1
Loop
ch.Range("W110").Copy _
sh.Range("H" & (k + res_1))
ch.Range("AI110").Copy _
sh.Range("I" & (k + res_1))
res_1 = Empty
End If
End If