How to use "range" with a text value of an integer value

Status
Not open for further replies.

KhallP

Board Regular
Joined
Mar 30, 2021
Messages
157
Office Version
  1. 2016
Platform
  1. Windows
I need to use the "range" parameter to select a specific cell, it happens that when I "run" the program it gives an error and says "The specified dimension is not valid for the current graph"


Error
--------------------------------------------
If Range("H(CStr(k))").Value = "" Then
-------------------------------------------
Workbooks(myRecentFile).Worksheets(counter).Range("W110").Copy
Workbooks("EEC QEC.xlsm").Worksheets(counter2).Range("H(CStr(k))").Paste
Workbooks(myRecentFile).Worksheets(counter).Range("AI110").Copy
Workbooks("EEC QEC.xlsm").Worksheets(counter2).Range("I(CStr(k))").Offset(0, 1).Paste

Else
Do Until ActiveCell.Value = ""
ActiveCell.Offset(1, 0).Select
res = res + 1
Loop

Workbooks(myRecentFile).Worksheets(counter).Range("W110").Copy
Workbooks("EEC QEC.xlsm").Worksheets(counter2).Range("H(CStr(k + res))").Paste
Workbooks(myRecentFile).Worksheets(counter).Range("AI110").Copy
Workbooks("EEC QEC.xlsm").Worksheets(counter2).Range("I(CStr(k + res))").Offset(0, 1).Paste

End If[/CODE]
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi KhallP,

Code:
If Range("H" & CStr(k)).Value = "" Then
Ciao,
Holger
 
Upvote 0
Solution
Hi KhallP,

Code:
If Range("H" & CStr(k)).Value = "" Then
Ciao,
Holger

Now in that line appear:


"object doesn't support this property or method"


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" & CStr(k)).Value = "" Then
Workbooks(myRecentFile).Worksheets(counter).Range("W110").Copy
Workbooks("EEC QEC.xlsm").Worksheets(counter2).Range("H" & CStr(k)).Paste
Workbooks(myRecentFile).Worksheets(counter).Range("AI110").Copy
Workbooks("EEC QEC.xlsm").Worksheets(counter2).Range("I" & CStr(k)).Offset(0, 1).Paste

Else
Do Until ActiveCell.Value = ""
ActiveCell.Offset(1, 0).Select
res = res + 1
Loop

Workbooks(myRecentFile).Worksheets(counter).Range("W110").Copy

Error
-----------------------------------------------------------------------------------------
Workbooks("EEC QEC.xlsm").Worksheets(counter2).Range("H" & CStr(k + res)).Paste
------------------------------------------------------------------------------------------

Workbooks(myRecentFile).Worksheets(counter).Range("AI110").Copy
Workbooks("EEC QEC.xlsm").Worksheets(counter2).Range("I" & CStr(k + res)).Offset(0, 1).Paste

End If
 
Upvote 0
Hi KallP,

the lines you mention by now to raise an exception have not been part of the opening question.

You do not need to convert a numeric value to a string in order to use it either in a range or cells object - they both expect numbers for the rows. And as I cannot see where counter2 gets any value I regret but I think nobody would be able to answer that problem only by looking at this thread..

Ciao,
Holger
 
Upvote 0
Hi KallP,

the lines you mention by now to raise an exception have not been part of the opening question.

You do not need to convert a numeric value to a string in order to use it either in a range or cells object - they both expect numbers for the rows. And as I cannot see where counter2 gets any value I regret but I think nobody would be able to answer that problem only by looking at this thread..

Ciao,
Holger
Rich (BB code):
Public Sub WriteCells()
    
    res = 0
    
    Sheets("QEC 1.2 - montagem").Select
    k = Cells(Rows.Count, "H").End(xlUp).Row
    
    ws = Workbooks(myRecentFile).Sheets.Count
    ws2 = Workbooks("EEC QEC.xlsm").Sheets.Count
    
    For counter = 1 To ws
        For counter2 = 1 To ws2
            Set ch = Workbooks(myRecentFile).Worksheets(counter)
            Set sh = ActiveWorkbook.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 & CStr(k + 1)").Value = "" Then
                        Workbooks(myRecentFile).Worksheets(counter).Range("W110").Copy
                        Workbooks("EEC QEC.xlsm").Worksheets(counter2).Range("H & CStr(k + 1)").Paste
                        Workbooks(myRecentFile).Worksheets(counter).Range("AI110").Copy
                        Workbooks("EEC QEC.xlsm").Worksheets(counter2).Range("I & CStr(k + 1)").Offset(0, 1).Paste
                    
                    Else
                    Do Until ActiveCell.Value = ""
                        ActiveCell.Offset(1, 0).Select
                        res = res + 1
                    Loop
                
                        Workbooks(myRecentFile).Worksheets(counter).Range("W110").Copy
                        Workbooks("EEC QEC.xlsm").Worksheets(counter2).Range("H & CStr(k + res + 1)").Paste
                        Workbooks(myRecentFile).Worksheets(counter).Range("AI110").Copy
                        Workbooks("EEC QEC.xlsm").Worksheets(counter2).Range("I & CStr(k + res + 1)").Offset(0, 1).Paste
                
                    End If
                End If
            End If
        Next counter2
    Next counter
    
End Sub
 
Upvote 0
Hi KhallP,

Code:
 If Range("H & CStr(k + 1)").Value = "" Then
should read
Code:
 If Range("H" & k + 1).Value = "" Then
Also for the other lines of code.

Maybe spread this on the other threads you started as well.

Holger
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

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