Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating Lines Using A Macro 1

Status
Not open for further replies.

SandraF

Programmer
Jan 25, 2001
28
US
Hello.

I have two worksheets in excel. One worksheet is where i will input rows of data. Each row represents a record. When I run the macro that I want to create (but haven't yet), I want the macro to take that info that I typed in, and copy it to the other worksheet. The only problem is that I can have as many lines as I need, and do not know how to create a macro that will do this.
 
An easy way to do this is to cycle through each row, checking for data. Let's assume that if there is a record, column A will contain info. The sheet of records in this sample is called 'Records'.
Code:
Public Sub TransferData()
    Dim iRow As Long
    Dim dataSht As Worksheet
    
    Set dataSht = Sheets("Records")
    iRow = 1    'First row of data
    Do While Len(dataSht.Range("A" & iRow).Text) > 0
        'This row contains a record
        'Copy to another sheet
        iRow = iRow + 1
    Loop
    MsgBox "The last record is on Row: " & (iRow - 1)
End Sub
Hope this helps!
 
Of course, sandra, my first question is, why don't you group the worksheets prior to entering the data? Not the same row?
techsupportgirl@home.com
Brainbench MVP for Microsoft Word
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top