Cannot comprehend part of VB code

sncb

Board Regular
Joined
Mar 17, 2011
Messages
137
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Hi All,

Could anyone out there 'translate' this code for me please. I dont have to use VB much much Ive been asked to make some modifications.



If IsDate(Sheets("Hold").Range("R" & Rows.Count).End(xlUp).Value) Then
LastDate = Sheets("Hold").Range("R" & Rows.Count).End(xlUp).Value
Else
LastDate = Date
End If


Thanks in adv
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Hi All,

Could anyone out there 'translate' this code for me please. I dont have to use VB much much Ive been asked to make some modifications.



If IsDate(Sheets("Hold").Range("R" & Rows.Count).End(xlUp).Value) Then
LastDate = Sheets("Hold").Range("R" & Rows.Count).End(xlUp).Value
Else
LastDate = Date
End If


Thanks in adv

Well without knowing the structure of your workbook, Id say it checks if last cell with a value in it in column R, of sheet "HOLD" contains a date, if it does it sets the the variable LastDate to contain this vale, if not, it sets the LastDate variable to contain the current date.
 
Upvote 0
This
Range("R" & Rows.Count)
Rows.Count = the number of rows available to an excel Sheet.
In xl2003 = 65536
In xl2007 = over 1 million (not sure the exact number).

so "R" & Rows.Count = R65536

Range("R65536").End(xlUp)
the red part then simulates pressing CTRL + UP arrow
So it goes to the last occupied cell in column R
then IsDate tests if that cell contains a Date
If it does, it sets the varaible LastDate to = that date

If the last cell in column R is NOT a date,
Then the variable is assigned Today's date.
 
Upvote 0
On 2nd thoughts, I dont understand this part though....

"If it does, it sets the varaible LastDate to = that date"

are you're saying, it goes from R1 down to the last row where it finds a date and then it does what?
 
Upvote 0
No, it goes from R65536 (in xl2003) then UP (xlUp) to the first cell it encounters that contains a value.
This is the LAST cell in the column that contains a value.
 
Upvote 0

Forum statistics

Threads
1,196,269
Messages
6,014,346
Members
441,816
Latest member
Klingon1960

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