Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Can't make loop macro work - help?
I started this yesterday and got some help with this macro:
Sub test() Dim Counter As Integer For Counter = Cells(Rows.Count, "A").End(xlUp) To 1 Step -1 If Cells(Counter, 1) = 1 Then Cells(Counter, 1).EntireRow.Insert Cells(Counter, 1).FormulaR1C1 = "Record Type" Cells(Counter, 2).Value = "Process Date/Time" Cells(Counter, 3).Value = "Customer Number" Cells(Counter, 4).Value = "Customer Name" Cells(Counter, 5).Value = "Enrollment Type" Cells(Counter, 6).Value = "Filler" End If Next Counter End Sub When I changed it to : If Cells(Counter,1) = 2 then It woudn't loop through my spread sheet. It would only put the row over the first 2 row found. (I have a spread sheet where column A is either a 01, 02, 03 or 04. I need to insert a header line over each one but 01 has one set of headers, 02 a second and so forth. Each number will happen multiple times so I need the macro to loop) So I tried making something new and came up with this: Sub enter_headers() Dim rangetosearch As Object Dim cellelement As Object Dim counter As Integer Dim Record As Integer counter = 1 Set rangetosearch = Sheet1.Range(Cells(counter, 1), Cells(counter, 1)) Set cellelement = rangetosearch.Cells For Each cellelement In rangetosearch Record = cellelement.Value If Record = 2 Then Cells(counter, 1).EntireRow.Insert Cells(counter, 1).FormulaR1C1 = "Record Type" Cells(counter, 2).Value = "Process Date/Time" Cells(counter, 3).Value = "Customer Number" Cells(counter, 4).Value = "Customer Name" Cells(counter, 5).Value = "Enrollment Type" Cells(counter, 6).Value = "Filler" End If counter = counter + 1 Next End Sub However with this one my rangetosearch line won't work. I am trying to tell it to search all the way thorugh column A for anything beginning with 02. (and it will expand eventually to include all 01, 02, 03, and 04) Am I way off base with this one? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Can't make loop macro work - help?
|
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Make table query will work in datasheet view but will not make tab | Excel Discussion (Misc queries) | |||
how do I debug my Excel macro & make it actually WORK? | Excel Programming | |||
How do I make a macro work in one worksheet only | Excel Programming | |||
Macro to make a cell work like a check | Excel Programming | |||
Help with macro to make it loop through coloums | Excel Programming |