VBA: if cell isn't empty, copy contents. if empty, move to next row.

jpringle1

New Member
Joined
Jan 4, 2019
Messages
7
OK so i just need a simple piece of VBA code which does the following things:

if cell B2 isn't empty, assign its value to a variable.
if it is empty, run this same code against the next row.
Continue until the bottom of the table is reached.

this piece of code of code is going to be adapted for a bigger project, so i will likely come back to ask for help on modifications a few times after this has been answered. The reason i only want a part of it answered at a time is because i want to understand the code so i can adapt it myself for future projects, and i'm not sure exactly which direction i want to take the code in yet.

Thank you
 
Hi TotallyConfused, perhaps the link below will clear up for you the difference ways of referencing sheets :)

https://www.ozgrid.com/VBA/excel-vba-sheet-names.htm

Btw, shorter code doesn't necessarily mean better code :biggrin:

Hello Mark

I want to say THANKS for sending me this link. I've known about the three different ways to refer to a sheet, as tabname, codname and index, but what I didn't know was that it is possible to change the way sheets are referred to throughout a workbook. I would have changed each line of code one line at a time, which in a long program, could be quite a job. To say nothing of the disaster if even one reference was missed. There is a treasure chest full of other information on that site too. I have bookmarked that place for future reference and I have a feeling I'll be returning there quite often.

TotallyConfused
 
Upvote 0

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Somehow my last posting #11 duplicated itself here. Maybe one of the moderators can delete this for me. Thanks.
Sorry about this.

TotallyConfused
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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