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

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

northwolves

Well-known Member
Joined
Jun 21, 2006
Messages
1,128
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
  5. 2010
  6. 2007
  7. 2003 or older
Platform
  1. Windows
Not very cleary with your needs.Provide more details,please.
 

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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,899
Messages
5,834,299
Members
430,275
Latest member
Halis

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