Vba concatenate 2 columns that have a currency

VBA learner ITG

Active Member
Joined
Apr 18, 2017
Messages
272
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi all,

Any advice would be appreciated on this!


Column P of my workbook is a numerical column and Column Q is a Currency sign indicator, I need to add the Currency sign indicator to the front of the cell in column P or at the end depending on the currency sign indicator.

£ = UK Pounds
P = UK Pence



[TABLE="width: 500"]
<tbody>[TR]
[TD]Column P[/TD]
[TD]Column Q[/TD]
[/TR]
[TR]
[TD]1.50[/TD]
[TD]£[/TD]
[/TR]
[TR]
[TD]50[/TD]
[TD]P[/TD]
[/TR]
</tbody>[/TABLE]


so the output would look like the below
[TABLE="width: 500"]
<tbody>[TR]
[TD]Column P[/TD]
[TD]Column Q[/TD]
[/TR]
[TR]
[TD]£1.50[/TD]
[TD]£[/TD]
[/TR]
[TR]
[TD]50P[/TD]
[TD]P[/TD]
[/TR]
</tbody>[/TABLE]


Is this achieving in column P without adding another column to the table using VBA?

I have tried the below code but it will only concatenate the value at the front of the cell value.

Code:
 For i = 2 To Cells(Rows.Count, "P").End(xlUp).Row
    Cells(i, "P").Value = Cells(i, "Q").Value & "" & Cells(i, "P").Value
Next i
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
A suggestion:
Code:
For i = 2 To Cells(Rows.Count, "P").End(xlUp).Row
    Select Case Cells(i, "Q").Value
        Case Is = "£": Cells(i, "P").Value = Cells(i, "Q").Value & Cells(i, "P").Value
        Case Is = "p": Cells(i, "P").Value = Cells(i, "P").Value & Cells(i, "Q").Value
    End Select
Next i
 
Last edited:
Upvote 0
Hi JackDanIce,

Thank you for your help, i have learnt something new today :)


A suggestion:
Code:
For i = 2 To Cells(Rows.Count, "P").End(xlUp).Row
    Select Case Cells(i, "Q").Value
        Case Is = "£": Cells(i, "P").Value = Cells(i, "Q").Value & Cells(i, "P").Value
        Case Is = "p": Cells(i, "P").Value = Cells(i, "P").Value & Cells(i, "Q").Value
    End Select
Next i
 
Upvote 0
Another way :
Code:
Dim p$: p = Range("P2:P" & Cells(Rows.Count, "P").End(3).Row).Address
Dim q$: q = Range(p).Offset(0, 1).Address
Range(p) = Evaluate("IF(" & q & "=""P""," & p & "&" & q & "," & q & "&" & p & ")")
 
Last edited:
Upvote 0
hi Footoo

Thank you for your assistance, both codes have been very helpful and useful as i have learnt something new.

Another way :
Code:
Dim p$: p = Range("P2:P" & Cells(Rows.Count, "P").End(3).Row).Address
Dim q$: q = Range(p).Offset(0, 1).Address
Range(p) = Evaluate("IF(" & q & "=""P""," & p & "&" & q & "," & q & "&" & p & ")")
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,160
Members
453,021
Latest member
Justyna P

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