What is FirstR=0 and LastR = 0 in VBA?

vbanewbie68

Board Regular
Joined
Oct 16, 2021
Messages
171
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hello

I have been given a macro to transform an original data from a platform website into a imported report for our database.
In one area in the sub statement as see below I am struggling to read that and feel its not readable to me.
I don't under what is FirstR = 0 and LastR = 0.

Can you help me to read this please?

VBA Code:
Sub CopyData()

lastimport = mbook.Sheets("ImportDates").Cells(1, 1).End(xlDown).Value

Set tempsht = tempbook.Sheets(1)
FirstR = 0
LastR = 0
dateC = findCol("EventDate", tempsht)
For x = 2 To tempsht.Cells(1, 1).End(xlDown).Row
    If FirstR = 0 And tempsht.Cells(x, dateC) > lastimport Then
        FirstR = x
    End If
   
    If tempsht.Cells(x, dateC).Value < Date Then
        LastR = x
    End If

Next x

If FirstR > 0 Then
    mbook.Sheets("ImportDates").Cells(1, 1).End(xlDown).Offset(1, 2).Value = LastR - FirstR - 1
    mbook.Sheets("ImportDates").Cells(1, 1).End(xlDown).Offset(1, 1).Value = Date
    mbook.Sheets("ImportDates").Cells(1, 1).End(xlDown).Offset(1, 0).Value = Date - 1
Else
    MsgBox ("No new rows to import. If this is wrong check the 'LastImportDates' sheet")
    tempbook.Close SaveChanges:=False
    End
End If
rsheet.Activate
tempsht.Rows(FirstR & ":" & LastR).Copy rsheet.Cells(2, 1)

End Sub
 
Last edited by a moderator:

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
It just sets the initial values for those variables to 0.
 
Upvote 0
Solution
Why variables value to 0? What is that mean?Please send me an example?
 
Upvote 0
What you posted is an example. What do you not understand about it?
 
Upvote 0
When the First Row to the last row =0. Does it makes the worksheet is empty. No values in it?
 
Upvote 0
No. They are just variables that re used to store row numbers. They do not affect anything on the sheet.
 
Upvote 0
Ok. I think I get it. What is about this line? Last Row take away First Row and then minus 1?

LastR - FirstR - 1
 
Upvote 0

Forum statistics

Threads
1,223,250
Messages
6,171,036
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