vangog
12-28-2021, 05:55 AM
Code like this:
' Definition of variable Nemocnice (in Nemocnice Sheet)
Sheets("Nemocnice").Select
Selection.CurrentRegion.Select
Set Nemocnice = Range(Selection.Address)
29257
' Source table named as "OriginalTable" contains columns NID and Nemocnice.
OriginalSheet.Select
Selection.CurrentRegion.Select
Set OriginalTable = Range(Selection.Address)
29258
And here I have the problem:
NID_nemocnice = OriginalTable.Offset(1, NemocniceCol - 2).Resize(OriginalTable.Rows.Count - 1, 2)
For Each rw In NID_nemocnice
Set MyVar = rw.Cells(1).Value
m = Application.Match(rw.Cells(1).Value, Nemocnice.Columns(2), 0)
If Not IsError(m) Then
OriginalTable.Cells(m, NemocniceCol - 1).Value = rw.Cells(2).Value
End If
Next rw
29259
So when I enter the For Each loop, the variable rw is empty. As a result it crashes on the yellow line:
Set MyVar = rw.Cells(1).Value
Error 424 Object required.
But I can see in the Watch (see image) that the nemocnice is filled with values (almost 40,000 items).
' Definition of variable Nemocnice (in Nemocnice Sheet)
Sheets("Nemocnice").Select
Selection.CurrentRegion.Select
Set Nemocnice = Range(Selection.Address)
29257
' Source table named as "OriginalTable" contains columns NID and Nemocnice.
OriginalSheet.Select
Selection.CurrentRegion.Select
Set OriginalTable = Range(Selection.Address)
29258
And here I have the problem:
NID_nemocnice = OriginalTable.Offset(1, NemocniceCol - 2).Resize(OriginalTable.Rows.Count - 1, 2)
For Each rw In NID_nemocnice
Set MyVar = rw.Cells(1).Value
m = Application.Match(rw.Cells(1).Value, Nemocnice.Columns(2), 0)
If Not IsError(m) Then
OriginalTable.Cells(m, NemocniceCol - 1).Value = rw.Cells(2).Value
End If
Next rw
29259
So when I enter the For Each loop, the variable rw is empty. As a result it crashes on the yellow line:
Set MyVar = rw.Cells(1).Value
Error 424 Object required.
But I can see in the Watch (see image) that the nemocnice is filled with values (almost 40,000 items).