Just cant get range to work!

ffialho

New Member
Joined
Apr 27, 2012
Messages
16
Hi All,

running a quick code:

Basically column 49 will receive the DATE FORMAT value of column 39.
What I want is instead of running from line 2 to 100000 ( For k = 2 to 100000) - to use the lastrow! In this case just to calculate in filled space

dim lastrow as long
dim lascolumn as long
dim k as long

lastrow = sht.Range("A" & Rows.Count).End(xlUp).Row
lastcolumn = sht.Cells(1, Columns.Count).End(xlToLeft).Column + 1

Codes running here

With sht.Cells(1, lastcolumn)
.Value = "Expire_Date"
For k = 2 to 100000 --> change this to something like - use the lastrow and do it thru the lastrow range ( lets say from row 2 to 6503 ) or ( 2 to 2900) # of rows changes depending on the period used to generate the spreadsheet.
Cells(k,49).Value = CDate (Cells(k,39).Value)
Next k
End With

Other codes running here

Any help will be appreciated
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Well, you are already calculating the last row, so you should just be able to change this:
VBA Code:
For k = 2 to 100000
to this
VBA Code:
For k = 2 to lastrow

However, your lastrow calculation is referencing sheet "sht", which I do not see being set to anything anywhere:
Rich (BB code):
lastrow = sht.Range("A" & Rows.Count).End(xlUp).Row

Is this being set somewhere else in your code that you haven't shown us?
 
Upvote 0
Solution
Hi Joe4! I did set the mentioned "sht" just forgot to share in the code! ;) changing to lastrow worked as a charm! thanks for help!
 
Upvote 0
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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