Help by creat a counter

nader

Board Regular
Joined
Sep 26, 2005
Messages
135
Code:
PageSetup.PrintArea = "[COLOR="Blue"]Where I have to insert the counter[/COLOR]"

I want to make this code limit the columns (C2,D2,E2) that has data from the frist cell to the last cells in the columns by insert a counter.
 
Last edited:

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.
Not very cleary with your needs.Provide more details,please.
 
Upvote 0
Hi, Nader,

To my sense this is what you need.
Code:
Sub test()
Dim LR As Long
 
    With Range("C2:D" & Rows.Count)
    LR = .Find("*", .Cells(1, 1), xlFormulas, xlPart, xlByRows, xlPrevious, False, False).Row
    End With
ActiveSheet.PageSetup.PrintArea = "C2:D" & LR
End Sub
kind regards,
Erik
 
Upvote 0
I tried this code to set area only the red data in these columns, but it didn't succes with me.
By the way there is a row between the data in red and black.
Code:
Dim i As Integer
For i = 1 To Rows.End(xlUp).Count
ActiveSheet.PageSetup.PrintArea = "C2:D2" & i
Next i

10 4000
22 3900
23 3800
5 1500
99 1200


7 1000
8 900
8 700
55 800
2 550
2 550
 
Upvote 0
your question was "to the LAST cell"
so you mean till the first blank?

the code you displayed was not the code provided
if you react to this reply I will see what to do
 
Upvote 0
try this
Code:
Sub test()
Dim LR As Long
 
    LR = Range("C2").End(xlDown).Row 

ActiveSheet.PageSetup.PrintArea = "C2:D" & LR
End Sub
typed off hand, typos possible
you can record a macro while pressing Ctrl + Arrow Down and you will get similar syntax

kind regards,
Erik
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,728
Members
448,987
Latest member
marion_davis

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