![]() |
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? |
Can't make loop macro work - help?
|
All times are GMT +1. The time now is 08:13 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com