VBA Copying cells from different sheets if cell is not empty

JaccoVis90

New Member
Joined
Oct 30, 2015
Messages
34
Hallo guys,

I have a question.
For a project i want to make a total sheet where al the products from other Sheets are collected.
(To also deal with the other sheets i would, at this point, copy the loop and change the sheet name, (not all sheets need to be implemented))

In the "basic" sheets there are the products with underneed them specification.
In the row of the name of the product there is the total price which i need. (I hope it is understandible)

Is this code the best way to go?

Code:
Sub testtest()

Dim i As Integer
Dim counter As Integer
Dim j As Integer
Dim a As String
Dim b As String


i = ThisWorkbook.Sheets("Blad1").Range("B" & Rows.Count).End(xlUp).Row

counter = 1
MsgBox (i) 'it is just for testing

Do Until counter = i


If ThisWorkbook.Sheets("Blad").Range("A" & counter) = Empty Then


Else
j = ThisWorkbook.Sheets("Blad2").Range("A" & Rows.Count).End(xlUp).Row
ThisWorkbook.Sheets("Blad2").Range("A" & j + 1) = ThisWorkbook.Sheets("Blad1").Range("A" & counter).Value
ThisWorkbook.Sheets("Blad2").Range("B" & j + 1) = ThisWorkbook.Sheets("Blad1").Range("B" & counter).Value
ThisWorkbook.Sheets("Blad2").Range("C" & j + 1) = ThisWorkbook.Sheets("Blad1").Range("J" & counter).Value
End If
counter = counter + 1

Loop

MsgBox "Einde"

End Sub

Thanks in advance
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Forum statistics

Threads
1,223,248
Messages
6,171,027
Members
452,374
Latest member
keccles

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