VBA to Copy paste cell description if there is not data in a particular cell

zmaniar

New Member
Joined
Sep 24, 2021
Messages
10
Office Version
  1. 2019
Platform
  1. MacOS
Hello. I am try to figure out a VBA to resolve this issue. I have got the state from the bank but the description is in multiline. I need get everything in one line.

The current sitatuation is

Column A | Column B
Row 1. 23.
11-Jun-21​
UtilityBill Paid 2326****11
FRM 191*****03
TO HBL 406******3
KESC0001 040*******29
thru Digital Banking
12-Jun-21​
Debit Card/POS 8******4925
PKR ***9.00 114925 1206 53******
E********O KARACHI
14-Jun-21​
Debit Card/POS 98101*****218
PKR 1****.00 00**8 1406 5366**
B******K KARACHI

What I need is
11-Jun-21​
UtilityBill Paid 2**********80611 FRM 191*********3 TO HBL 406*********03 K*********01 040********* thru Digital Banking
12-Jun-21​
Debit Card/POS 8*********14925 PKR 1*********.00 114925 1206 5*********190 E*********O KA*********CHI


Can anyone help?
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try this
VBA Code:
Sub Arrange()

Dim n As Long, m As Long
Dim cell As Range, rngData As Range

Set rngData = Range("B1", Cells(Rows.Count, "B").End(xlUp)).Offset(0, -1)

n = 0
For Each cell In rngData
    If Not cell = "" Then
        n = n + 1
        Range("D" & n) = cell.Value
        Range("E" & n) = Range("B" & cell.Row) & " "
    Else
        Range("E" & n) = Range("E" & n).FormulaR1C1 & " " & Range("B" & cell.Row)
    End If
Next

End Sub
 
Upvote 0
Solution
Thank you Zot.

It's replicating Column A & B to D & E. Nothing changed
 
Upvote 0
I did not understand what you meant. This is what I got when I ran the code
Book1
ABCDE
111-Jun-21UtilityBill Paid 2326****1111-Jun-21UtilityBill Paid 2326****11 FRM 191*****03 TO HBL 406******3 KESC0001 040*******29 thru Digital Banking
2FRM 191*****0312-Jun-21Debit Card/POS 8******4925 PKR ***9.00 114925 1206 53****** E********O KARACHI
3TO HBL 406******314-Jun-21Debit Card/POS 98101*****218 PKR 1****.00 00**8 1406 5366** B******K KARACHI
4KESC0001 040*******29
5thru Digital Banking
612-Jun-21Debit Card/POS 8******4925
7PKR ***9.00 114925 1206 53******
8E********O KARACHI
914-Jun-21Debit Card/POS 98101*****218
10PKR 1****.00 00**8 1406 5366**
11B******K KARACHI
Sheet1
 
Upvote 0
Strange. If I copy the data from above and run the script it works. But I am running it on the actual data it isn't working.

Any way I can put the excel file here?
 
Upvote 0
Strange. If I copy the data from above and run the script it works. But I am running it on the actual data it isn't working.

Any way I can put the excel file here?
I actually copy paste your data there ?

The tool to select range on sheet capture and paste is XL2BB (the right most icon)

You need to install the Add-In. After paste it looks like rubbish. To view result click Preview. Click it again to go back to writing mode.

Are you sure your column is A and B?
 
Upvote 0

Forum statistics

Threads
1,214,957
Messages
6,122,466
Members
449,086
Latest member
kwindels

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