Excel - Combine Line One with Line Two

RudeBoy

Active Member
Joined
Feb 2, 2003
Messages
431
Office Version
  1. 365
Platform
  1. Windows
When I run the Macro it deletes all the data here is my data
It was working last week but this time it is deleting everything but the first two lines?
Am using this code:
Sub combineRows()
Dim ws As Worksheet, r As Long, lr As Long, cell As Range
Set ws = ActiveSheet
lr = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row
Application.ScreenUpdating = False
For r = lr To 3 Step -1
Set cell = ws.Cells(r, "A")
If cell = "" Then
cell.Offset(-1, 2) = cell.Offset(, 1)
cell.EntireRow.Delete
End If
Next r
End Sub


Sheet1
AB
Incidents Project - Jobs Converted-k.xlsm
1EDIBCBD9
2228 //BADRC EXEC EDIP0022,JOBNAME=EDIBCBD9,
3EDIBCBM9
4316 //BADRC EXEC EDIP0022,JOBNAME=EDIBCBM9,
5EDIBCBW9
6316 //BADRC EXEC EDIP0022,JOBNAME=EDIBCBW9,
7EDIBCBY9
8315 //BADRC EXEC EDIP0022,JOBNAME=EDIBCBY9,
9EDIBC601
1083 //BADRC EXEC EDIP0022,JOBNAME=EDIBC601,
11EDIBC604
12959 //BADRC EXEC EDIP0022,JOBNAME=EDIBC604,
13EDIBC605
1464 //BADRC EXEC EDIP0022,JOBNAME=EDIBC605,
15EDIBC606
16145 //BADRC EXEC EDIP0022,JOBNAME=EDIBC606,
17EDIBC607
18103 //BADRC EXEC EDIP0022,JOBNAME=EDIBC607,
19EDIBC608
20357 //BADRC EXEC EDIP0022,JOBNAME=EDIBC608,
21EDIBC609
2242 //BADRC EXEC EDIP0022,JOBNAME=EDIBC609,
23EDIBC611
2458 //BADRC EXEC EDIP0022,JOBNAME=EDIBC611,
CellConditionCell FormatStop If True
Cells with Conditional Formatting
A:ACell Value="N"textNO
A:ACell Value="Y"textNO
 
Change from
VBA Code:
For i = .Cells(Rows.Count, 2).End(xlUp).Row To 7 Step -1

To
VBA Code:
For i = .Cells(Rows.Count, 2).End(xlUp).Row To 2 Step -1
 
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
You're welcome,
regards, JLG
I tried to run it on a large selection and it said this subscript out of range?? What does that mean
 

Attachments

  • Subscript out of range.jpg
    Subscript out of range.jpg
    10.2 KB · Views: 5
Upvote 0
You're welcome,
regards, JLG

Maybe it is the change of data that gave me a out of range

MASTER - ACTIVE EDI & QEDI Jobs-as-of-7-31-2020-i.xlsm
AB
454n11 CRITICALITY OF JOB:_A
455nEDIBCHM1
456n28 CRITICALITY OF JOB: B
457nEDIBCHM2
458n28 CRITICALITY OF JOB: B
459nEDIBCHM3
460n28 CRITICALITY OF JOB: B
461nEDIBCHM4
462n28 CRITICALITY OF JOB: B
463nEDIBCHM5
464n28 CRITICALITY OF JOB: B
465nEDIBCHM6
466n28 CRITICALITY OF JOB: B
467nEDIBCHM7
468n9 CRITICALITY OF JOB: B
469nEDIBCHM8
Sheet15


The 1st Line will always Begin with EDI
The 2nd line could vary on what Data is there but All I want to do is Combine the Data Like This:
MASTER - ACTIVE EDI & QEDI Jobs-as-of-7-31-2020-i.xlsm
ABCDE
1nEDI#CO0111 CRITICALITY OF JOB: A
2nEDI#HI0111 CRITICALITY OF JOB: A
3nEDI#MA0111 CRITICALITY OF JOB: A
4nEDI#NW0111 CRITICALITY OF JOB: A
5nEDI#000111 CRITICALITY OF JOB: A
6nEDI#000211 CRITICALITY OF JOB: A
Sheet15
 
Upvote 0
The error message looks like it is from a sheet code module because there is no 'Debug' button on the message box. Unless the procedure title begins with 'Private' it should be installed in a puublic code modules. Those are the ones inserted by the user and are automaticfally numbered by Excel. The Subscript out of Range message indicates that an object that the code is telling it to use cannot be found. Could be caused by changing moving the code from one workbook to another where the variables reference the worng objects, or code is changed by the user and no longer points to an object that is valid or the object name is mispelled in the code or characters are added or deleted from and object name, Objects are workbboks, worksheets, conrols and userforms primarily. There are others like cells and ranges of cells.

If the code was in the correct code module, you could clidk the 'Debug' button when it errors and it would show you the line of code that the problem originates from.
 
Upvote 0
The error message looks like it is from a sheet code module because there is no 'Debug' button on the message box. Unless the procedure title begins with 'Private' it should be installed in a puublic code modules. Those are the ones inserted by the user and are automaticfally numbered by Excel. The Subscript out of Range message indicates that an object that the code is telling it to use cannot be found. Could be caused by changing moving the code from one workbook to another where the variables reference the worng objects, or code is changed by the user and no longer points to an object that is valid or the object name is mispelled in the code or characters are added or deleted from and object name, Objects are workbboks, worksheets, conrols and userforms primarily. There are others like cells and ranges of cells.

If the code was in the correct code module, you could clidk the 'Debug' button when it errors and it would show you the line of code that the problem originates from.
I cut n pasted the data from a .txt file
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,209
Members
453,023
Latest member
alabaz

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