PDA

View Full Version : New to VBA Coding



on7june
03-14-2014, 07:50 AM
I am trying to understand the logic inside a macro which i need to replicate in my application. While going through it found the following statement and i could not understand, can you guys explain me?
Cells(1, 3).Resize(lastrow, 1).Name = "NonNamed"
Let me know if you need more details.

Kenneth Hobs
03-14-2014, 07:53 AM
Welcome to the forum!

Press F1 in or near a command word for help in the VBE. Resize expands C1 to the number of rows defined by lastrow and just that one column. Name, sets the name reference for that resized range.

on7june
03-14-2014, 08:33 AM
Thanks a lot, so here we are defining a new range and named it as "NonNamed". Below is my understanding.
Cells(1,3) = C1,
lastrow=3
so the new resized range is from c1:C3 and it is referred as NonNamed.
From now on in the VBA code where ever we use "NonNamed" it refers to this new range?

Kenneth Hobs
03-14-2014, 08:41 AM
Right.


Sub ken()
Dim lastrow As Long, r As Range
lastrow = 3
Set r = Cells(1, 3).Resize(lastrow, 1)
r.Name = "NonNamed"
MsgBox "r.Name's address: " & r.Address
MsgBox "NonNamed's address: " & Range("NonNamed").Address
End Sub