macro to generate next number

Hi, i need a macro to look in sheet 2 column A and look at the last filled 
cell. In the  last filled cell i have a number. When i run macro, i need to 
generate (in sheet1 A1) the number from the last filled cell +1.

EX:
sheet 2 last filled cell = 29
sheet1 after macro i need to have in A1 = 30

Can this be done?
Thanks!
0
Utf
3/9/2010 8:58:01 PM
excel.misc 78881 articles. 4 followers. Follow

6 Replies
1549 Views

Similar Articles

[PageSpeed] 17

Hi,

Yuo can have a macro if you want but you don't need one, try this

=OFFSET(Sheet2!A1,COUNTA(Sheet2!A:A)-1,0)
-- 
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that 
introduces the fewest assumptions while still sufficiently answering the 
question.


"puiuluipui" wrote:

> Hi, i need a macro to look in sheet 2 column A and look at the last filled 
> cell. In the  last filled cell i have a number. When i run macro, i need to 
> generate (in sheet1 A1) the number from the last filled cell +1.
> 
> EX:
> sheet 2 last filled cell = 29
> sheet1 after macro i need to have in A1 = 30
> 
> Can this be done?
> Thanks!
0
Utf
3/9/2010 9:08:01 PM
Hi Mike. I really need a macro.
I am using some macros and i need to use this macro along with the other ones.
But i really don't know how to make this work.
Can you help me with a macro?
Thanks!


"Mike H" wrote:

> Hi,
> 
> Yuo can have a macro if you want but you don't need one, try this
> 
> =OFFSET(Sheet2!A1,COUNTA(Sheet2!A:A)-1,0)
> -- 
> Mike
> 
> When competing hypotheses are otherwise equal, adopt the hypothesis that 
> introduces the fewest assumptions while still sufficiently answering the 
> question.
> 
> 
> "puiuluipui" wrote:
> 
> > Hi, i need a macro to look in sheet 2 column A and look at the last filled 
> > cell. In the  last filled cell i have a number. When i run macro, i need to 
> > generate (in sheet1 A1) the number from the last filled cell +1.
> > 
> > EX:
> > sheet 2 last filled cell = 29
> > sheet1 after macro i need to have in A1 = 30
> > 
> > Can this be done?
> > Thanks!
0
Utf
3/9/2010 9:17:01 PM
A macro it is then

Sub Sonic()
Dim LastRow As Long
Set SrcSht = Sheets("Sheet2")
Set DstSht = Sheets("Sheet1")
LastRow = SrcSht.Cells(Cells.Rows.Count, "A").End(xlUp).Row
DstSht.Range("A1").Value = SrcSht.Range("A" & LastRow)
End Sub

-- 
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that 
introduces the fewest assumptions while still sufficiently answering the 
question.


"puiuluipui" wrote:

> Hi Mike. I really need a macro.
> I am using some macros and i need to use this macro along with the other ones.
> But i really don't know how to make this work.
> Can you help me with a macro?
> Thanks!
> 
> 
> "Mike H" wrote:
> 
> > Hi,
> > 
> > Yuo can have a macro if you want but you don't need one, try this
> > 
> > =OFFSET(Sheet2!A1,COUNTA(Sheet2!A:A)-1,0)
> > -- 
> > Mike
> > 
> > When competing hypotheses are otherwise equal, adopt the hypothesis that 
> > introduces the fewest assumptions while still sufficiently answering the 
> > question.
> > 
> > 
> > "puiuluipui" wrote:
> > 
> > > Hi, i need a macro to look in sheet 2 column A and look at the last filled 
> > > cell. In the  last filled cell i have a number. When i run macro, i need to 
> > > generate (in sheet1 A1) the number from the last filled cell +1.
> > > 
> > > EX:
> > > sheet 2 last filled cell = 29
> > > sheet1 after macro i need to have in A1 = 30
> > > 
> > > Can this be done?
> > > Thanks!
0
Utf
3/9/2010 9:26:01 PM
On Tue, 9 Mar 2010 13:26:01 -0800, Mike H
<MikeH@discussions.microsoft.com> wrote:

>A macro it is then
>
>Sub Sonic()
>Dim LastRow As Long
>Set SrcSht = Sheets("Sheet2")
>Set DstSht = Sheets("Sheet1")
>LastRow = SrcSht.Cells(Cells.Rows.Count, "A").End(xlUp).Row
>DstSht.Range("A1").Value = SrcSht.Range("A" & LastRow)
>End Sub

+1 should be added at the end of the last statement like this:

DstSht.Range("A1").Value = SrcSht.Range("A" & LastRow) + 1

Lars-�ke
0
Lars
3/9/2010 9:41:20 PM
Hi Mike, your first formula gives me an error, and the macro retrieves the 
last number. I need to display last number +1.
Am i doing something wrong?
Thanks!

"Mike H" wrote:

> A macro it is then
> 
> Sub Sonic()
> Dim LastRow As Long
> Set SrcSht = Sheets("Sheet2")
> Set DstSht = Sheets("Sheet1")
> LastRow = SrcSht.Cells(Cells.Rows.Count, "A").End(xlUp).Row
> DstSht.Range("A1").Value = SrcSht.Range("A" & LastRow)
> End Sub
> 
> -- 
> Mike
> 
> When competing hypotheses are otherwise equal, adopt the hypothesis that 
> introduces the fewest assumptions while still sufficiently answering the 
> question.
> 
> 
> "puiuluipui" wrote:
> 
> > Hi Mike. I really need a macro.
> > I am using some macros and i need to use this macro along with the other ones.
> > But i really don't know how to make this work.
> > Can you help me with a macro?
> > Thanks!
> > 
> > 
> > "Mike H" wrote:
> > 
> > > Hi,
> > > 
> > > Yuo can have a macro if you want but you don't need one, try this
> > > 
> > > =OFFSET(Sheet2!A1,COUNTA(Sheet2!A:A)-1,0)
> > > -- 
> > > Mike
> > > 
> > > When competing hypotheses are otherwise equal, adopt the hypothesis that 
> > > introduces the fewest assumptions while still sufficiently answering the 
> > > question.
> > > 
> > > 
> > > "puiuluipui" wrote:
> > > 
> > > > Hi, i need a macro to look in sheet 2 column A and look at the last filled 
> > > > cell. In the  last filled cell i have a number. When i run macro, i need to 
> > > > generate (in sheet1 A1) the number from the last filled cell +1.
> > > > 
> > > > EX:
> > > > sheet 2 last filled cell = 29
> > > > sheet1 after macro i need to have in A1 = 30
> > > > 
> > > > Can this be done?
> > > > Thanks!
0
Utf
3/9/2010 9:50:01 PM
It's working.
Thanks!

"puiuluipui" wrote:

> Hi, i need a macro to look in sheet 2 column A and look at the last filled 
> cell. In the  last filled cell i have a number. When i run macro, i need to 
> generate (in sheet1 A1) the number from the last filled cell +1.
> 
> EX:
> sheet 2 last filled cell = 29
> sheet1 after macro i need to have in A1 = 30
> 
> Can this be done?
> Thanks!
0
Utf
3/9/2010 10:30:01 PM
Reply:

Similar Artilces:

Chart to represent sale number by individual contrubtion vs total
I need help on how to create a chart to represent sales number by individual contributor vs total. E.g. Alvin = $50 Mary = $150 John = $80 Kate = $120 Total = $400 The chart should show a graphical representation of $400 as the total, and it shows how each person contribute to the chart. Hi, One way would be to plot the data, not including the total as a stacked column. Alternately, you could plot the data without the total as a column chart and then plot the total as a line on the same chart. Just make a second series with each item the total. -- If this helps, please click th...

Macro warning with no macros
I have a workbook that when I try to open it I get the warning tellin me it contains macros and asking whether I want to Enable or Disabl them. I put no macros, no VB scripts, nothing at all in the workboo other than standard Excel formulas and some charts. I developed it i Excel 2002, SP-2, but have moved it back and forth between tw computers, the other which has Excel 97. Regardless of whether Enable or Disable or change the security settings so as not to get th warning, once the workbook is open even if I go t Tools-Macro-Macros... it lists no macros. How can I find out what's cau...

counting numbers if certain criteria are met?
I have two columns. the first has single digits between 0 and 9, th second has x's with blank spaces in between. Anyone know how to count or mark all the 2's in the first column that also have an x in th second column? Don't want to just count ALL the 2's -- Message posted from http://www.ExcelForum.com Hi Try something like this: =SUMPRODUCT((A2:A1000=2)*(B2:B1000="x")) -- Andy. "judoist >" <<judoist.17uhhk@excelforum-nospam.com> wrote in message news:judoist.17uhhk@excelforum-nospam.com... > I have two columns. the first has single ...

Macro
Can anybody tell me how to kick off a macro automatically as file is opened? Regards ...

generating .csv file
Hi, Is there any process (Code) to generate .csv files to all entities in MSCRM at a time. regards, sailaja. I think you are not clear with question. 1. You can export data to .csv file or excel file from any entity 2. You can export customization to .xml file which are enttities list etc. -- Regards, Imran MS CRM Certified Professional http://microsoftcrm3.blogspot.com Chat with me on MSN / Gmail / Skype : ID Is :.. mscrmexpert@gmail.com "sailaja.crm@gmail.com" wrote: > Hi, > Is there any process (Code) to generate .csv files to all entities in > MSCRM at a ...

Macro
Version: 2008 Operating System: Mac OS X 10.4 (Tiger) Processor: intel Hi, I'm thinking of buying Mac: Office 2008, but before I do I want to check that I will be able to download Scritpsmart collection of templates without any glitches: <http://www.bbc.co.uk/writersroom/scriptsmart/faq.shtml> Does anyone know if I can do this? Regards, SP. In article <ee98ff5.-1@webcrossing.caR9absDaxw>, StregaItalia@officeformac.com wrote: > Version: 2008 > Operating System: Mac OS X 10.4 (Tiger) > Processor: intel > > Hi, > > I'm thinking of buying Mac: Of...

Run macro automatically.
How do I make a macro run automatically when a worksheet it is attached to is loaded? right click on the sheet tab>view code>left window worksheet>right window activate -- Don Guillett SalesAid Software donaldb@281.com "Excel macro" <Excel macro@discussions.microsoft.com> wrote in message news:DD7AF1E3-9263-4523-AC49-A43ABA1AB9D0@microsoft.com... > How do I make a macro run automatically when a worksheet it is attached to is > loaded? I am unable to find "activate " when I right click on worksheet. ( i assume that you are referring to the windo...

Help with macro/and or formula?
Perhaps this is a silly question, but i just can't figure out how t format this worksheet. The problem is that a lot of the cells hav numbers in them with negative signs in the back instead of in the fron (ie. 23-) and i was wondering if anyone knew of a macro/formula i coul use to quickly fix this problem for all the cells. I would b extremely grateful. Thanks -- brefed1 ----------------------------------------------------------------------- brefed15's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=3557 View this thread: http://www.excelforum.com/showthre...

Quote Number
I would like for users to go into a form and reserve a quote number. Would like the quote number to be auto-assigned using mmddyy (then count 01 to xx for the day) followed by their initials. Basically result would be 02280801TR for the first then 02280802TR etc....Not mandatory for the Initials if you could solve the autonumber mixed date field...Initials could be another field in the database and could combine later. Thanks Tony, I would place the below on the AddNew button: DoCmd.GoToRecord , , acNewRec Me.txtQuoteID = StrReverse(Format(Date, "mm")) & Format(Date, &quo...

Attached Toolbars Macros
Excel 2003 I have a custom tool bar, this tool bar has several items, each item is pointing to a VBA code. This tool bar is attached to the worksheet. I've copied this spreadsheet to several computers. After I copied the spreadsheet I decided to rename the spreadsheet, after I renamed the spreadsheet the Toolbar Item's macros were still pointing to the old name, I reasigned each tool bar item to the current spreadsheet, saved the spreadsheet and everything was working on my computer, but when I re-copied the new spreadsheet to other computers and I clicked on the Toolbar Item...

Protected sheets and running macros
i have a sheet with a macro ran by a normal button at the top. Howeve when i protect the worksheet where ever i click on the sheet the macr executes. Can any one offer any advice on how to stop this? Thanks Robert -- Message posted from http://www.ExcelForum.com hi, i am not able to reproduce the problem, hence i may not be able t provide a panacea for that issue. here is what i suggest. i have a sheet that has a macro that is run when a control toolbo button (that is, not a form button) is clicked. this sheet is protected based on the user logged in. what i have don is to protect t...

Macro to remove rows?
Hi, I receive thousands of rows of data from an extract that comes from a database. The data extract automatically generates page headers that need to be removed, and I would love to automate this process. The headers do have a pattern to them, but I'm not clever enough to figure out a good way to use that to write a macro. The first row of the header starts with hyphens ------------------------------- Then there's a variable number of rows of header data to delete followed by another row of hyphens ------------------------------- Then 2 additional rows that must be deleted. The nu...

Macro Freezes Reading Pane
I have a macro that Sends/Receives Tasks from Project Server into Outlook Tasks. Everything is working fine, except one weird thing that happens. I have the Timer set on the macro and it starts as soon as Outlook starts. The macro gets the tasks from ProjectServer every hour. As soon as the macro starts running the Reading pane freezes in the Inbox. If i stop the macro then Reading pane is back to normal. Can anyone please tell me if there is something I can do in VBA to fix this annoying issue. Thanks a lot ...

Calling on a macro within a macro!
Hey All!! Quick Question - How do you call up a macro within a current macro? I have one big macro and I need it to jump to several other macros when it runs! Does it matter where the other macros are stored or is it better to have them all in one module? Help appreciated Thnx! Hi Mellowe, '=============>> Public Sub Main() 'Your code Call One 'your code End Sub '<<============= '=============>> Public Sub One() MsgBox "Hi from One" End Sub '<<============= > Does it matter where the other macros are stored or ...

shortcut keys to macros
Hi, Is it at all possible to assign shortcut keys to macros in Outlook? Thx, Hans ...

Can i print copy numbers?
At my job we must print copies of databases and keep track of them. We only print 100 copies at a time. Is there a way to make it automaticly put "1 of 100" or "copy 1 of 100" in the footer?? You could run a little macro: Option Explicit Sub testme() Dim iCtr As Long For iCtr = 1 To 3 '100 when you're ready With ActiveSheet .PageSetup.RightFooter = "Copy " & iCtr & " of 100" .PrintOut preview:=True 'false when you're ready End With Next iCtr End Sub I used 1 to 3 and pri...

Macro that password protects a sheet
I am attempting to create a macro that can open a protected sheet, change something, and then protect it again. I continue to have an issue with the macro not entering the password. Is this possible to do/fix? Thanks, Ryan ..open password="mypassword" -- Don Guillett SalesAid Software donaldb@281.com "Ryan" <Ryan@discussions.microsoft.com> wrote in message news:D4780ED8-CA1D-4284-97BC-3576160D998E@microsoft.com... > I am attempting to create a macro that can open a protected sheet, change > something, and then protect it again. I continue to have an iss...

what's the shortcut key for 'go to next page' ?
Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel Hi all, <br><br>I came across the case, <br> I wanna jump to the next new page while i was doing my paper. <br> Under windows os, its shortcut key is 'control + enter'. <br> How about Mac os ? <br><br><i>am looking forward your reply. Thanks in advance.</i> > I wanna jump to the next new page while i was doing my paper. <br> > Under windows os, its shortcut key is 'control + enter'. <br> > How about Mac os ? &l...

help Unable to record Macro !!!!!!!
I want to record a macro in excel.But as soon as I click record Macro it says "unable to record" macro. Got no help in excel help.I do this same thing in word and it's working. Please help It's urgent for me !!!1 Have a look here http://groups.google.com/groups?as_epq=unable%20to%20record&as_ugroup=microsoft.public.excel.* -- Don Guillett SalesAid Software donaldb@281.com "ash" <anonymous@discussions.microsoft.com> wrote in message news:3e0b01c42ae5$45333e00$a401280a@phx.gbl... > I want to record a macro in excel.But as soon as I click > record...

Footer Macro?
Hi Months ago I read a Public Sub Macro that read the selection of a drop down list in a combo box and placed it in the center Footer at the same time it also placed the date in the right Footer and tme in the left footer. I have searched most of the regular sites including this one and cannot find it anywhere --- Can anyone help with my search. Any help much appreciated Cheers ---- Mully ...

Keyboard Shortcut in Macro
Hi all i'v created macro with Keyboard Shortcut Ctrl+b . now i want to change it to Ctrl+z how can i do it . regards Tools-->Macro-->Macros. Select (don't open!) your macro, and hit the Options button. :) ************ Hope it helps! Anne Troy www.OfficeArticles.com "osaka78" <osaka78@discussions.microsoft.com> wrote in message news:1721A458-212D-4446-8209-494A459EE428@microsoft.com... > Hi all > i'v created macro with Keyboard Shortcut Ctrl+b . now i want to change it > to > Ctrl+z > how can i do it . > > regards THE MACRO IS NO...

Macros have been disabled but there is no macro
when I open a specific doc the info bar at the top says "Macros have been disabled", but when I hit Alt+F11 I can't find any VB or a module to remove. Why is it telling me about macros? Other docs don't give me this prompt. I thought I might have to enable macros to see the code. When I enabled macro, it said "do you want to save changes to this doc?" it flickered and came back as if immediately reopened. Any ideas? I could copy and paste the text into a new doc but I'd be interested to be able to strip off this problem. The doc is an internal IT ...

on Error goto 0 &on error resume next
Hi, In my macro,before I access the objects,i wrote "on error resume next" to trap any error that might occur.My questions are: 1) do I need to write somewhere in my code "on Error goto 0", to disable the error handeler.since with or without using "on error goto 0" in my macro,I do not see any differences. 2) is that enough to use "on error resume next" only once at the begining of my codes when I want to access the objects,or should I keep reaping it.since with or without using "on error resume next" in my macro,I do not see any difference. ...

sort numbers based on initial digit.
running excell 2002. I have a list of part numbers starting 1xxxxxxxxx (8 digits total) and ending 9(4 digits). Default will put the larger number of digits last but I need the first number of the sequence to be the primary sort number. eg: 12345678, 2345, 6, 789, 8, 99999. etc. Any simple solution? Hi! One way.... Use a helper column and extract the first 8 digits from the p/n then sort on that column. Assume p/n's are in the range A1:A100: A1 = 12345678, 2345, 6, 789, 8, 99999 Say the helper column is column D. In D1 enter this formula: =LEFT(A1,8)*1 This will extract the...

printing only even-numbered pages in a newsletter
how do i print, say, even-numbered pages in a Publisher newsletter that I have mail merged with Outlook Thank you. What version of Publisher do you have? If you have Adobe Acrobat full version, you can make a PDF file which will give you that option. If you have a quality printer like a Kyocera or some model Canon printers, they have that option in the printer driver. -- The US should free all those illegally held prisoners they are torturing, abusing and denying human rights being held at Guantanamo Bay. ...