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:

Some videos you may like

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
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
 

nader

Board Regular
Joined
Sep 26, 2005
Messages
135
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
 

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832

ADVERTISEMENT

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
 

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832

ADVERTISEMENT

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
 

Watch MrExcel Video

Forum statistics

Threads
1,122,233
Messages
5,594,963
Members
413,954
Latest member
mrsandy

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
Top