Need help with a marco please

buster01

New Member
Joined
Jan 10, 2014
Messages
13
I originally posted a request for help with sorting, matching and adding data. JLGWhiz responded with the macro shown below. It works great and I really appreciate it. The problem I am having is getting it to work on the rows and columns of the sheet I need it to. The data is on sheet footing starting on row 127 through row 141 in Column B, C and D (see below example of data). I would like for the answer to show up starting on row 143 through 157 in the same column B, C and D. There is data above these rows but no data is below row 142 if this helps. Also I would like to use the same macro on another sheet. Sheet is FTG & Wall in the same folder. The data starts on row 284 through 298 Column B, C and D. I would like the answer to start in row 300 through 314 in column B, C and D. On this sheet there is data above and below these rows.
9" x 3'
3
25
12" x 2'6"
4
40
10" X 4'
5
33.3333
8" x 2'
3
50
9" x 3'
3
50
8" x 2'
3
25
6" x 1'6"
5
50
6" x 1'6"
5
25
10" x 4'
5
50
12" x 2'6"
4
33.3333
0
0
#DIV/0!
0
0
#DIV/0!
0
0
#DIV/0!
0
0
#DIV/0!
0
0
#DIV/0!
<tbody> </tbody>


1. Sub consItems()
2. Dim sh As Worksheet, lr As Long, sCell As Range
3. Set sh = Sheets(1) 'edit sheet name
4. lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
5. sh.Range("A2:A" & lr).EntireRow.Sort Range("A1"), xlAscending
6. For i = lr To 2 Step -1
7. With sh
8. Set sCell = .Cells(i - 1, 1).Offset(0, 2)
9. If Trim(.Cells(i, 1).Value) = Trim(.Cells(i - 1, 1).Value) Then
10. sCell = sCell.Value + sCell.Offset(1, 0).Value
11. Rows(i).Delete
12. End If
13. End With
14. Next
End Sub
I don’t know how to contact JLGWhiz directly. So If I have made a mistake by posting this in this manned I am sorry. I am new at this but I want to follow the rules. I really appreciate the help I have received.



 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
The first one is for sheets footing and the othe for FTG & wall.
Code:
Sub consItems2()
Dim sh As Worksheet, lr As Long, sCell As Range
Set sh = Sheets("footing") 'edit sheet name
lr = sh.Cells(Rows.Count, 2).End(xlUp).Row 'Find last row in column B
sh.Range("B127:D141").Sort Range("B127"), xlAscending 'Sort Range
    For i = 127 To 141 'Initialize loop with parameters
        If sh.Cells(i, 2) > 0 Then 'Eliminate zeroes from action
            With sh
                If .Cells(143, 2) <> "" Then
                     Set sCell = .Cells(Rows.Count, 2).End(xlUp)(2) 'establis variable for sum cell
                Else
                     Set sCell = .Cells(143, 2)
                End If
                If Trim(.Cells(i, 2).Value) = Trim(.Cells(i + 1, 2).Value) Then 'compare cells
                     .Cells(i, 2).Resize(1, 2).Copy sCell
                     'add col D for matched items
                     sCell.Offset(0, 2) = .Cells(i, 4).Value + .Cells(i + 1, 4).Value
                End If
            End With
        End If
    Next
End Sub

Sub consItems3()
Dim sh As Worksheet, lr As Long, sCell As Range
Set sh = Sheets("FTG & Wall") 'edit sheet name
lr = sh.Cells(Rows.Count, 2).End(xlUp).Row 'Find last row in column B
sh.Range("B254:D298").Sort Range("B254"), xlAscending 'Sort Range
    For i = 254 To 298 'Initialize loop with parameters
        If sh.Cells(i, 2) > 0 Then 'Eliminate zeroes from action
            With sh
                If .Cells(300, 2) <> "" Then
                    Set sCell = .Cells(Rows.Count, 2).End(xlUp)(2) 'establis variable for sum cell
                Else
                    Set sCell = .Cells(300, 2)
                End If
                If Trim(.Cells(i, 2).Value) = Trim(.Cells(i + 1, 2).Value) Then 'compare cells
                    .Cells(i, 2).Resize(1, 2).Copy sCell
                    'add col D for matched items
                    sCell.Offset(0, 2) = .Cells(i, 4).Value + .Cells(i + 1, 4).Value
                End If
            End With
        End If
    Next
End Sub
 
Last edited:
Upvote 0
Mr. JLGWhiz I appreciate your response very much and I apologize for the way the information is displayed
so I am trying it in a different format. Hopefully it won't shove all the information to one side.
The last two Marco you sent me do not work. It is probably me. But anyway I am going to try this again.
This is my first time to post on any site.
The first Macro you sent works fine except I can't get it adjusted to work on the worksheets I need it to
Below is a copy of one of the worksheet I would like for it to work on. The work sheet name is footings.
All of the data starting at column B row 284 through column C row 298 is compiled from information above
I would like to start this Marco on column B row 301 through column D row 315 I will have more information
below row 317. When I run the Marco you first sent me on a test page. The Marco ran on top of the data,
also it gives me an error on this line Set sCell = .Cells (I - 1, 1) .Offset (0, 2) However it would run
I have tried to adjust the Marco but can't seem to get it to work
Columns
BCD
Rows
283Length of L BarsSize of L Bars# of Bars
2849" x 3'325
28512" x 2'6"440
28610" X 4'534
2878" x 2'350
2889" x 3'350
2898" x 2'325
2906" x 1'6"550
2916" x 1'6"525
29210" x 4'550
29312" x 2'6"434
29400#DIV/0!
29500#DIV/0!
29600#DIV/0!
29700#DIV/0!
29800#DIV/0!
299
300Answer I am Looking For
3019" x 3'375
3028" x 2'375
30312" x 2'6"474
30410" X 4'584
3056" x 1'6"575
306000
307000
308000
309000
310000
311000
312000
313000
314000
315000
316
I need the same set up as above on another worksheet called FTG & Wall. The data starts on column
B row 284 through D 298. I would like it to run starting on column B row 300 through D row 314.
<colgroup><col width="64" style="width: 48pt;"> <col width="141" style="width: 106pt; mso-width-source: userset; mso-width-alt: 4910;"> <col width="120" style="width: 90pt; mso-width-source: userset; mso-width-alt: 4189;"> <col width="75" style="width: 56pt; mso-width-source: userset; mso-width-alt: 2606;"> <tbody> </tbody>
 
Upvote 0

Forum statistics

Threads
1,203,617
Messages
6,056,312
Members
444,858
Latest member
ucbphd

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top