Setting lastrow [to activecell column last row] as the vba loops along....Please advice.

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
I'm looping through all the col till it is blank.
If col if 1st row is not blank i want to define lastrow to this col last row. for example
range("A" & rows.count).end(xlup).row
i want "A" row above to be x row...

I think i'm making sense...please help me out;

Code:
[/FONT]
[FONT=Courier New]Sub test()
Dim LastCol As Integer, c As Integer, myrng as range
LastCol = ActiveSheet.UsedRange.Columns(ActiveSheet.UsedRange.Columns.Count).Column

For c = 1 To LastCol
  If Cells(1, c).Value <> "" Then[/FONT]
[FONT=Courier New]     x= Cells(1, c).Value[/FONT]
[FONT=Courier New][COLOR=blue][I][B]     lastrow = ?? c column last row[/B][/I][/COLOR][/FONT][FONT=Courier New] [/FONT]
[FONT=Courier New]     set myrng = c.offset(1,0).resize(lastrow)[/FONT]
[FONT=Courier New]End If
Next c
End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
set myrng = range(cells(1,c.column),cells(rows.count,c.column).end.(xlup))
? untested
 
Upvote 0
p45cal, thanks for helping....
It is retuning compile error...identifier or bracketed expression...
;)
 
Upvote 0
Set myrng = Range(Cells(1, c), Cells(Rows.Count, c).End(xlUp))

Code:
Sub test()
Dim LastCol As Integer, c As Integer, myrng As Range
LastCol = ActiveSheet.UsedRange.Columns(ActiveSheet.UsedRange.Columns.Count).Column
For c = 1 To LastCol
    If Cells(1, c).Value <> "" Then
        x = Cells(1, c).Value
        Set myrng = Range(Cells(1, c), Cells(Rows.Count, c).End(xlUp))
       ' myrng.Select
    End If
Next c
End Sub
 
Upvote 0
I also tried this way but still errors...

Please help :(
Sub Test()
Dim lr As Long
lr = Cells(Columns(ActiveCell.Column), Rows.Count).End(xlUp).Row
ActiveCell.Resize(lr).copy
End Sub
 
Upvote 0
p45cal, thanks again for helping....it is working perfect now...
Set myrng = Range(Cells(1, c), Cells(Rows.Count, c).End(xlUp))

Code:
Sub test()[/FONT]
[FONT=Courier New]Dim LastCol As Integer, c As Integer, myrng As Range[/FONT]
[FONT=Courier New]LastCol = ActiveSheet.UsedRange.Columns(ActiveSheet.UsedRange.Columns.Count).Column[/FONT]
[FONT=Courier New]For c = 1 To LastCol[/FONT]
[FONT=Courier New]    If Cells(1, c).Value <> "" Then[/FONT]
[FONT=Courier New]        x = Cells(1, c).Value[/FONT]
[FONT=Courier New]        Set myrng = Range(Cells(1, c), Cells(Rows.Count, c).End(xlUp))[/FONT]
[FONT=Courier New]       ' myrng.Select[/FONT]
[FONT=Courier New]    End If[/FONT]
[FONT=Courier New]Next c[/FONT]
[FONT=Courier New]End Sub[/FONT]
[FONT=Courier New]

 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,799
Members
452,943
Latest member
Newbie4296

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