MrThor

New Member
Joined
Aug 13, 2018
Messages
36
Hi, I have a code which almost works fine for me. I have One sheet called Indata were I import values in column A. The number of cells varies between 3000-5000 approximately. My problem is that I put a For function with an i = 2 to 5000. This means that when the function reaches the first empty cell i column A it will fail. Anyone knows how to deal with it?

See code below:

Code:
Dim i As LongDim Resultat As Worksheet
Dim Indata As Worksheet
Dim noder As Worksheet
Dim Rg1 As Range, Rg2 As Range, Rg3 As Range, Rg4 As Range, Rg5 As Range


Set Resultat = Sheets("Resultat")
Set Indata = Sheets("Indata")
Set noder = Sheets("Alla noder")




With Application.WorksheetFunction


For i = 2 To 5000 Step 1




    Indata.Cells(i, 2).Value = .Index(noder.Range("B1:B300000"), .Match(Indata.Cells(i, 1), noder.Range("A1:A300000"), 0))
    Indata.Cells(i, 3).Value = .Index(noder.Range("C1:C300000"), .Match(Indata.Cells(i, 1), noder.Range("A1:A300000"), 0))
    Indata.Cells(i, 4).Value = .Index(noder.Range("D1:D300000"), .Match(Indata.Cells(i, 1), noder.Range("A1:A300000"), 0))
    Indata.Cells(i, 5).Value = .Index(noder.Range("E1:E300000"), .Match(Indata.Cells(i, 1), noder.Range("A1:A300000"), 0))


Next i


End With
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Try
Code:
for i=2 to range("A"&rows.Count).end(xlup).row
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0
Try
Code:
Sub MrThor()
   Dim Cl As Range
   Dim Noder As Worksheet, InData As Worksheet
   
   Set Noder = Sheets("Alla noder")
   Set InData = Sheets("Indata")
   
   With CreateObject("scripting.dictionary")
      For Each Cl In Noder.Range("A1", Noder.Range("A" & Rows.Count).End(xlUp))
         .Item(Cl.Value) = Cl.Offset(, 1).Resize(, 4)
      Next Cl
      For Each Cl In InData.Range("A2", InData.Range("A" & Rows.Count).End(xlUp))
         Cl.Offset(, 1).Resize(, 4).Value = .Item(Cl.Value)
      Next Cl
   End With
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,454
Messages
6,124,931
Members
449,195
Latest member
Stevenciu

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