Solved

Using a macro to add data to worksheets in XL 2003

Posted on 2011-03-25
5
194 Views
Last Modified: 2012-06-27
I have a worksheet that keeps track of conference room reservations. I have 4 workbooks each with one quarter of the year for 2011. For the second quarter, on each worksheet for the workbook (see attached), I need to insert 17 Central 4 cells below 17 North on each sheet. So for instance, on the April sheet, 17 Central is on A 30, A 68, etc. I have entered 4 manually, but would need a macro to automate this process for the remainder of the April sheet and the other two months in this workbook, and in the workbooks containing the remaining two quarters of the year.
Conference-Rooms.xls
0
Comment
Question by:contrain
5 Comments
 
LVL 8

Accepted Solution

by:
wchh earned 500 total points
ID: 35219952
Try Macro below
Sub Insert()
   Dim Worksheet As Worksheet
   Dim i As Integer
   For Each Worksheet In ThisWorkbook.Worksheets
       With Worksheet
       For i = 2 To .Cells(Worksheet.Rows.Count, "A").End(xlUp).Row
           If Trim(.Cells(i, 1).Value) = "17 North" Then
            .Cells(i + 4, 1).Value = "17 Central"
           End If
       Next i
       End With
    Next Worksheet
            
End Sub

Open in new window

0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 35220276
A word of caution:

>>   Dim i As Integer

Never, ever, EVER declare a row-counting variable as Integer.  The moment you get to Row 32,768, you will get a runtime error.

Just don't use Integer, period.  Use Long instead.  In the 70's it made senseto save every byte you could in your programming, but that was 40 years ago.

:)
0
 
LVL 6

Expert Comment

by:FernandoFernandes
ID: 35220731
I second that ! :)
0
 
LVL 8

Expert Comment

by:wchh
ID: 35228183
I also agreed. For this example, integer is good enough but long is the best.
0
 

Author Closing Comment

by:contrain
ID: 35234888
This worked and gave me what I wanted. I also appreciate the other Expert's comments on what to look out for in macros.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
create excel pivot chart 12 44
.Range Set 25 78
Excel calculate based on 'x' in column 2 25
vba delete dups is not working 35 16
Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question