convert text to number based on multiple headers

excel01noob

Board Regular
Joined
Aug 5, 2019
Messages
93
Office Version
  1. 365
  2. 2016
Hi

I have a dataset for which I need to first convert the data of several columns (from text to number) based on the column header

I don't want to define the column position as it varies from time to time, but the column header will always have the same header name.
In some occasions, some of the headers might not appear in the data set.

The header names most frequent are:

Quantity
Amount
Original currency Amount

These should be converted into numbers with 2 decimals

How do I get around this?
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
version is Office 365, I have done the updates but still not able to install the powerquery add-in
 
Upvote 0
I said: update profile on mrexcel (Account details)
anyway you have Power Query built-in so use it
 
Upvote 0
version is Office 365,
Please update your Account details with that information (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

You could try this macro ..
VBA Code:
Sub TextToNumber()
  Dim Hdr As Variant
  Dim rFound As Range
  
  Const myHeaders As String = "Amount|Quantity|Original currency Amount"
  
  For Each Hdr In Split(myHeaders, "|")
    Set rFound = Rows(1).Find(What:=Hdr, LookAt:=xlWhole, MatchCase:=False)
    If Not rFound Is Nothing Then
      With Intersect(rFound.EntireColumn, ActiveSheet.UsedRange)
        .NumberFormat = "0.00"
        .Value = .Value
      End With
    End If
  Next Hdr
End Sub
 
Upvote 0
COM add in.jpg


I don't have the Power query add-in available when selecting thorugh COM Add-in.
these are the only ones.

I updated my account details with the excel version I am using in the company
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,208
Members
448,554
Latest member
Gleisner2

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