Rabu, 09 Juli 2014

Re: [ExcelVBA] Need help with sequential line numbering

 

What is the value of the cell in column "A" of the previous row?
I tried your code, and it worked if the previous cell was numeric,
but if it was ALPHAnumeric (PC84461) then it did not work and I
received "Run-time Error 13 type mismatch".
because you cannot add a number to text.
 
You could check:

    If (IsNumeric(ActiveCell.Offset(-1, 0).Value)) Then
        ActiveCell.Value = ActiveCell.Offset(-1, 0).Value + 1
    Else
        MsgBox ActiveCell.Offset(-1, 0).Value & Chr(13) & "is non-numeric"
    End If
 
Paul
-----------------------------------------
"Do all the good you can,
By all the means you can,
In all the ways you can,
In all the places you can,
At all the times you can,
To all the people you can,
As long as ever you can." - John Wesley
-----------------------------------------

From: "jefff@rogers.com [ExcelVBA]" <ExcelVBA@yahoogroups.com>
To: ExcelVBA@yahoogroups.com
Sent: Tuesday, July 8, 2014 3:39 PM
Subject: [ExcelVBA] Need help with sequential line numbering

 
Hi All Experts,
I am trying to create a VBA program that will insert a new line and will populate column A with sequential line numbering based on the previous line numbers' value. Please do not confuse line number with row number, as there are some rows at the top that will contain static text data. Here is my attempt so far, but I am getting a "Run-time Error 13 type mismatch" in the last line of code. Any help is appreciated.

Option Explicit

Private Sub cmdTransferData_Click()
   
    Dim EmptyRow As Long
   
    EmptyRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 1).Row

'Insert Row
    Cells(EmptyRow, 1).Rows("1:1").EntireRow.Select
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
   
'Number First Cell In Row
    Cells(EmptyRow, 1).Select
    ActiveCell.Value = ActiveCell.Offset(-1, 0) + 1




__._,_.___

Posted by: Paul Schreiner <schreiner_paul@att.net>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (2)
----------------------------------
Be sure to check out TechTrax Ezine for many, free Excel VBA articles! Go here: http://www.mousetrax.com/techtrax to enter the ezine, then search the ARCHIVES for EXCEL VBA.

----------------------------------
Visit our ExcelVBA group home page for more info and support files:
http://groups.yahoo.com/group/ExcelVBA

----------------------------------
More free tutorials and resources available at:
http://www.mousetrax.com

----------------------------------

.

__,_._,___

Tidak ada komentar:

Posting Komentar